Intelligent Automation & Macro Software  

Go Back   Tethys Solutions Forums > Products Zone > Automation Anywhere
Register FAQ Search Today's Posts Mark Forums Read

Automation Anywhere Post messages and questions related to Automation Software here.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2010, 09:03 AM
TylerMitton TylerMitton is offline
Member
 
Join Date: Nov 2009
Posts: 93
Default SQL script not finishing and causing exit without warning

I have an SQL script command as follows:

IF NOT EXISTS (SELECT 1 FROM MyTable WHERE TimeStamp = '$CurrentDate$' AND Plant = $CurrentPlant$)
BEGIN
INSERT INTO MyTable
(TimeStamp_UTC, Plant, LoadKWh, LoadKVarh, GenerationKWh, GenerationKVarh)
VALUES
(
'$CurrentDate$',
$CurrentPlant$,
$Filedata Column(3)$,
$Filedata Column(4)$,
$Filedata Column(5)$,
$Filedata Column(6)$
)

SELECT 1
END
ELSE
BEGIN
SELECT 0
END

It checks to see if a record exists, and if it doesn't, it will insert it then return a dataset containing a single row with a single field with the value of 1.

If it does already exist, it will not insert anything and it will return a dataset with a single row with a single field with the value of 0.

The insert works properly and records are being inserted into my database. However, the dataset of "SELECT 1" after the insert is not being returned. If I create a loop to access the dataset return from that script, it will cause my task to exit this loop as well as all loops above this command (in my case I have 3 levels of loops and it exits all three... continuing the task on the next iteration of the upper most loop).

However, if the insert is not required and the "SELECT 0" dataset is returned, then there are no problems and I can access the value of 0 from $Dataset Column(1)$.

Is there a problem with doing an insert followed by a select in my script? I have tested the code in SQL Server Management studio and it runs fine and returns 1 if a record was inserted and 0 if a record was not inserted.
Reply With Quote
  #2 (permalink)  
Old 03-09-2010, 07:33 PM
forumsupport forumsupport is offline
Senior Member
 
Join Date: Apr 2007
Posts: 1,311
Default

Hello,

What we understand, you have created a stored procedure with mentioned SQL commands and are calling it from Automation Anywhere using 'Run Stored Procedure' Database command. Please correct if we are wrong.

In this case, unfortunately, currently 'Run Stored Procedure' Database command does not return value(s) however, the upcoming version (will release shortly) does support this feature. To get around this issue, you can log the return value to a text file, from where Automation Anywhere can fetch the results.

Hope that helps.
Reply With Quote
  #3 (permalink)  
Old 03-10-2010, 07:50 AM
TylerMitton TylerMitton is offline
Member
 
Join Date: Nov 2009
Posts: 93
Default

Hi, sorry, no I am not running a stored procedure. I am using the SQL Query option in the Database command. The query I am running is the code I pasted above. It does the insert fine if the record didn't already exist (which is what it is supposed to do). It also does the SELECT 0 fine if the record did already exist. But it wont do the SELECT 1 after doing an insert.

When it does do the SELECT 0 it returns the record properly... so it is able to return the dataset... just not after doing an insert.
Reply With Quote
  #4 (permalink)  
Old 03-12-2010, 07:17 AM
forumsupport forumsupport is offline
Senior Member
 
Join Date: Apr 2007
Posts: 1,311
Default

Hello,

Can you please try executing the same set of statements from your database manually? If it runs successfully from database then try inserting one more ‘Execute SQL’ command with ‘If Exist….’ statement. There would be total two ‘Execute SQL’ command one for ‘If Not Exist….’ and another one for ‘If Exist….’

Hope that helps.
Reply With Quote
  #5 (permalink)  
Old 03-15-2010, 10:49 AM
TylerMitton TylerMitton is offline
Member
 
Join Date: Nov 2009
Posts: 93
Default

Yes, the SQL runs successfully on my database manually. There is something about AA that is not receiving the dataset after the insert has occurred.

I've removed the insert from the SQL completely and left everything else the same. That allows me to get a value which I put into a parameter. If that value = 1, then I run another SQL INSERT to put the data into the database... not a great solution but it's the best I could do considering the bug with AA.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -7. The time now is 06:19 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 ©2007, Crawlability, Inc.
Copyright © 2003-2008 Tethys Solutions, LLC. All rights reserved