NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

how to retrieve more then one record from database

I am doing a SELECT FROM WHERE SQL statement on a database which returns more then one record. I want to retrieve certain column values from the selected records. How do I do that? If only one record is returned, I know I can do a data operation with operation set to 'Get-Retrieve Values from Record' and Record to operate on set to 'Current-Use current record'. I need to find out how to configure to data operation window in the case more then one record is returned by the preceding SQL statement. Depending on the number of records returned, I can dynamically create array variables to store the 'to be retrieved' column values, just dont know how to retrieve them.
 
Any help will be greatly appreciated.
 
Thanks
 
Anuj
0 Kudos
Message 1 of 9
(4,163 Views)
When you do an Edit Open SQL Statement, you will see a box labeled "Number of Records Selected". Create a TestStand numeric variable and point to it there. It will contain the number of records returned.
0 Kudos
Message 2 of 9
(4,151 Views)

I know about that, I am already retrieving the number of records returned into a local numeric variable. My question was how to retrieve the multiple records (some specific columns of those records) that get selected in the SELECT statement. Please read the original post again and see if you can understand the question.

 

 

 

0 Kudos
Message 3 of 9
(4,148 Views)
What is the difference between "multiple" records and "number" of records? A record is a single row with all of the columns in your select query. Multiple records are more than one row. Are you talking about returning an unknown number of columns from your select statement? Or do you want to know how to assign multiple columns to certain variables?

Message Edited by Dennis Knutson on 02-14-2006 08:49 AM

0 Kudos
Message 4 of 9
(4,138 Views)
I apologize for not being clear in explaining my problem, perhaps I should have posted an example. Anyways, I was able to figure out the solution. I was doing an 'Open SQL' statement which was selecting multiple records (rows) from a table in the dB. I was storing the number of records returned in a local variable. Then, I wanted to retrieve certain columns of all the selected rows (records). In the "Data operation", I was choosing the 'Record to operate on' as 'Current-Use Current Record'. Changing this field to 'Next-Fetch next record' fixed the problem. I then retrieved the values of those columns into a dynamically created array variable whose dimensions came from the local variable which stored the number of records returned in the SELECT SQL statement. 
 
Thanks
 
Anuj
Message 5 of 9
(4,118 Views)

Can some one give more details how to do it (retrieve more then one record from database) ?

 

I have attached my sequence file

0 Kudos
Message 6 of 9
(2,789 Views)

@Anuj wrote:
I apologize for not being clear in explaining my problem, perhaps I should have posted an example. Anyways, I was able to figure out the solution. I was doing an 'Open SQL' statement which was selecting multiple records (rows) from a table in the dB. I was storing the number of records returned in a local variable. Then, I wanted to retrieve certain columns of all the selected rows (records). In the "Data operation", I was choosing the 'Record to operate on' as 'Current-Use Current Record'. Changing this field to 'Next-Fetch next record' fixed the problem. I then retrieved the values of those columns into a dynamically created array variable whose dimensions came from the local variable which stored the number of records returned in the SELECT SQL statement. 
 
Thanks
 
Anuj

THANK YOU!Smiley Happy

0 Kudos
Message 7 of 9
(2,511 Views)

Hello,

I've faced the same problem. Could you please show how to create the array variable dynamically?

Thanks

 

 

0 Kudos
Message 8 of 9
(2,445 Views)

In TestStand 2017 - 32bit

The 'Number of records selected' always returns -1  --> this means, the DB connectivity in TestStand is not usable. (I am not sure if the problem is solved in TS 2019)

 

No. of returned records.png

 

as workaround, I used Python step in order to get data from DB

 

 

0 Kudos
Message 9 of 9
(2,443 Views)