Jump to content

Recommended Posts

Posted (edited)

Hi, I am using SQL.au3 (Chris Lambert v3.2) to connect and query a stored procedure, and it works except that my stored procedure returns 2 tables but this script is only seeing 1 of the tables.  How can I retrieve the 2nd table?  

When I run the query in mssql studio, it shows both tables, one right after the other.  

I'm doing a query like this:  $query = "exec spMyStoredProcedure".  The stored procedure returns 2 tables, but I only get 1 in AutoIt.

 

The stored procedure is like this:

SELECT * FROM [TableA];
SELECT * FROM [TableB];

So, I need to be able to do something like this:

DataTable tableA = ds.Tables[0];
DataTable tableB = ds.Tables[1];

 

 

Edited by ferbfletcher
Posted (edited)

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Returning more than a single resultset is against relational algebra fundations (and common sense as well).

@InunoTaishou,

What you recommend is a cross join between tables, not even close to what the OP expect to have working, deviant as it is.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
  On 12/29/2016 at 5:17 PM, jchd said:

Returning more than a single resultset is against relational algebra fundations (and common sense as well).

@InunoTaishou,

What you recommend is a cross join between tables, not even close to what the OP expect to have working, deviant as it is.

Expand  

You are mistaken, this is a standard thing and is used in many applications:

https://msdn.microsoft.com/en-us/library/ms131686.aspx

 

It is neither against common sense, nor it is deviant.

Posted

Did you look in MSDN example ?

https://msdn.microsoft.com/en-us/library/ms130978.aspx

Dim con As New ADODB.Connection  
  
con.ConnectionString = "Provider=SQLNCLI11;" _  
         & "Server=(local);" _  
         & "Database=AdventureWorks;" _   
         & "Integrated Security=SSPI;" _  
         & "DataTypeCompatibility=80;" _  
         & "MARS Connection=True;"  
con.Open  
  
Dim recordset1 As New ADODB.Recordset  
Dim recordset2 As New ADODB.Recordset  
  
Dim recordsaffected As Integer  
Set recordset1 =  con.Execute("SELECT * FROM Table1", recordsaffected, adCmdText)  
Set recordset2 =  con.Execute("SELECT * FROM Table2", recordsaffected, adCmdText)  
  
con.Close  
Set con = Nothing  

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 12/29/2016 at 6:26 PM, mLipok said:

Did you look in MSDN example ?

https://msdn.microsoft.com/en-us/library/ms130978.aspx

Dim con As New ADODB.Connection  
  
con.ConnectionString = "Provider=SQLNCLI11;" _  
         & "Server=(local);" _  
         & "Database=AdventureWorks;" _   
         & "Integrated Security=SSPI;" _  
         & "DataTypeCompatibility=80;" _  
         & "MARS Connection=True;"  
con.Open  
  
Dim recordset1 As New ADODB.Recordset  
Dim recordset2 As New ADODB.Recordset  
  
Dim recordsaffected As Integer  
Set recordset1 =  con.Execute("SELECT * FROM Table1", recordsaffected, adCmdText)  
Set recordset2 =  con.Execute("SELECT * FROM Table2", recordsaffected, adCmdText)  
  
con.Close  
Set con = Nothing  

 

Expand  

No, that is directly accessing the tables on the db, not using the stored procedure.

 

 

Posted

Could you privide this stored procedure ?
I want to see how data are exported to the outer space ;)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@ferbfletcher,

I'd hardly call MARS a "standard". Instead it's a pointless proprietary MS sugar inviting bad code.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
  On 12/29/2016 at 7:05 PM, mLipok said:

Could you privide this stored procedure ?
I want to see how data are exported to the outer space ;)

 

Expand  

It is a large complex procedure, however the contents of the procedure does not matter.  Whether it is complex, or a simple 2 line select as shown above, either way, there are 2 (or more) tables returned.

 

  On 12/30/2016 at 12:39 AM, jchd said:

@ferbfletcher,

I'd hardly call MARS a "standard". Instead it's a pointless proprietary MS sugar inviting bad code.

Expand  

Regardless, many developers use it, and in my case I have no control over changing the stored procedure.  I just receive whatever the procedure sends me.

 

UPDATE:

So, I did finally find the solution, and it is extremely simple.  Hopefully this will help someone else who runs across this in the future:

https://msdn.microsoft.com/en-us/library/ms677539(v=vs.85).aspx

The query handle returned by .Execute() contains the 1st table, like always, and do whatever you want with the data.

THEN, do .NextRecordset(), and the query handle will contain the next table, then again, do whatever you want with the data.

Basically, just add that one line, and it's done.

 

 

 

 

 

Posted
  On 12/31/2016 at 1:15 AM, ferbfletcher said:

It is a large complex procedure, however the contents of the procedure does not matter.  Whether it is complex, or a simple 2 line select as shown above, either way, there are 2 (or more) tables returned.

Expand  

I do not need to see entire procedure.
How they are returned to the outside of procedure ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...