I just discovered the ability to create a variable and specify that it can be used as a SQL parameter.
My old query looks like this: SELECT * FROM customers WHERE customerID=@custID
and I had created a parameter called @custID with type int.
I deleted the parameter and then created a variable called @custID and checked the box "Allow using as SQL parameter".
The report fails to run in the designer, crashing because of the "@" sign.
I changed the name of the variable to "custID" and my query to "SELECT * FROM customers WHERE customerID=custID".
It still fails to run, this time saying "Column custID is invalid".
How do you use a variable in the query?
How to use a variable in a SQL query
Re: How to use a variable in a SQL query
Found the answer to my question. Need to surround the variable in brackets. Also it must be wrapped in quote if it is a string. e.g. SELECT * from customers WHERE firstName='{name}'
https://www.stimulsoft.com/en/blog/arti ... ql-queries
https://www.stimulsoft.com/en/blog/arti ... ql-queries
-
- Posts: 6270
- Joined: Tue Mar 20, 2018 5:34 am
Re: How to use a variable in a SQL query
Hello,
Thank you for the information.
Thank you for the information.