How to use a variable in a SQL query
Posted: Tue Feb 07, 2023 4:23 am
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?
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?