SET @U = 'user_id in (405,255,585)'
SET @SQL = 'SELECT user_id FROM tbl_user WHERE ' + @U
EXEC(@SQL)
@U must alwas be a string variable, you could write the statement as
SET @U = '405'
SET @SQL = 'SELECT user_id FROM tbl_user WHERE user_id in (' + @U + ')'
but if you pass in an integer variable you will get a 'data type mismatch' error when you try and create the sting variable @STR. You have to convert the integer value to a string variable before you try and make the @SQL
It took me a few frustrated hours to work that out
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.