I hope that is a very simple question...I have a very simple query which works just fine:SELECT top 3 ResultFROM gbdb.dbo.TestsWHERE Result IS NOT NULL AND Var_Id in (392,514)
I need to be able to get the list of Var_Id from a table as a string and use it in this quesry as a parameter:Query 1:Select varlist from vartable where varid = 5It returns, say, the string '392,514'I want to do following:Alter Procedure spGetResults@txtParm_Vars varchar(20)ASBeginSet Nocount ON;SELECT top 3 ResultFROM gbdb.dbo.TestsWHERE Result IS NOT NULL AND Var_Id in (@txtParm_Vars)END
This one does not work - it complains that Syntax error converting the varchar value '392,514' to a column of data type int.Yes, Var_Id is defined as Int in table Tests, but why it is OK hard code '392, 514' as the IN list and it is not OK to supply same string as a value of a parameter? What would be a solution here?Thanks