09-02-2008 07:43 PM
I am trying to use a local variable within an open SQL step but I keep getting an error.
My sql command looks like this "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " + locals.CurrentSerialNo
If I replace the locals.CurrentSerialNo with an actual value such as below the statement works fine.
"SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " + " 'ABC001' "
Can someone tell me how to correctly format the statement to use a variable?
09-03-2008 12:31 AM
Hi,
It could be that locals.CurrentSerialNo does not exist and that its should be Locals.CurrentSerialNo (note the capital L) or that you haven't defined a string variable Locals.CurrentSerialNo in your sequence.
What was the actual error?
What version of TestStand are you using?
Regards
Ray Farmer
09-03-2008 04:42 AM
Hi,
I have attached the sequence file. What I have noticed is that the sql statement is not available in the Data Operation step.
Thanks
Stuart
09-03-2008 12:37 PM
Stuart,
I think the problem is that your locals.BoardDetailID is a number, but the expression is expecting a string so that it can use the + operator to concatinate. I think if you use the below (notice the addition of the str() function) it will work:
"SELECT BoardDetailID FROM BoardDetail WHERE SerialNumber = " + Str(Locals.BoardDetailID)
Also, just to clarify from above, the TestStand expression language is case-insensitive, so it doesn't matter if you use "Locals." or "locals.", they will work the same.
09-03-2008 02:43 PM
Hi,
Thanks for the reply. I have changed the required variable to a string, but with no success. I have reattached my updated sequence file and an image of the error.
When looking at the Data operation step I see that the sql statement is missing everything after the last quotation mark.
Thanks again,
Stuart
09-03-2008 03:10 PM
Hi,
All sorted. I changed the statement to look like the statement below and it worked
Thanks
Stuart
"SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " + "'" + Locals.CurrentSerialNo + "'"