NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the Open SQL Statement in Teststand

I have the following SQL Statement contained in an Open SQL Statement Step:
"SELECT TableA.ColumnA FROM TableA WHERE TableA.ColumnB = " + FileGlobals.HexNumericValue

ColumnB contains numeric data, and the FileGlobals.HexNumericData is also a Hex numeric value.

When executing the step I get:
Error executing substep 'Post'. Error In SQL Statement. Specified Value does not have the expected type (TSAPI).
-17308, specified value does not have the expected type.

I'm sure this is a SQL statement problem, but if I try the equivalent inside of SQL with a constant, then this works. I'm not sure of the rules for " or ' when putting the SQL statement inside the Teststand statements.
0 Kudos
Message 1 of 5
(3,753 Views)
To ADL -
The + operator is used for adding two numerics or appending two strings. Use the Str() function to convert FileGlobals.HexNumericValue to a string.

Scott Richardson (NI)
Scott Richardson
https://testeract.com
0 Kudos
Message 2 of 5
(3,753 Views)
Scott,
Thanks for the information to get me up and running, I do have one problem left now

"SELECT TableA.Manufacturer_Name FROM TableA WHERE ManufacturerNumber =" +str(FileGlobals.HexValue)

When this is converted into SQL, it appears as:

"SELECT TableA.Manufacturer_Name FROM TableA WHERE ManufacturerNumber = 0x6A", and this is a problem,as the last piece of this code is a string.

My question is this how do you convert in the post expression the Hex Value to a Decimal Value, as the value stored in the database is decimal. I have tried changing the FileGlobals.HexValue to unsigned type, but this didn't make any difference to the conversion,as the number is input as Hex.

RESULT
I had to go into each post expression and change the data type for the
fileglobal for this to work. Isn't the data type shared across all the instances?
0 Kudos
Message 3 of 5
(3,753 Views)
To ADL -
The STR function uses the format of the number variable itself for the conversion. So you either have to change the format of the file global to not be hex or you need to assign the value of the file global to a local that is not hex format and use STR on that variable. for example the expression could be, "Locals.Temp = FileGlobals.HexValue, SELECT ... + Str(Locals.Temp)". The last expression component is what is returned.

Scott Richardson (NI)
Scott Richardson
https://testeract.com
0 Kudos
Message 4 of 5
(3,753 Views)
To ADL -
I forgot that the Str() function also has optional parameters which you could use to force it to use a specific numeric format.
Use 'Str(FileGlobals.HexValue, "%$.13f")'

Scott Richardson (NI)
Scott Richardson
https://testeract.com
0 Kudos
Message 5 of 5
(3,753 Views)