Possible Duplicate:
using dynamic IN clause in MSSQL
I have one SQL statement which includes parameter such as @StartRow, @StartEnd, @CategoryIds.
SELECT * FROM StackOverFlow
WHERE
StartRow = @StartRow
AND StartEnd = @StartEnd
AND CategoryId IN (@CategoryIds)
When I set the parameters like below:
DECLARE @StartRow INT = 1;
DECLARE @StartRow INT = 10;
DECLARE @CategoryId NVARCHAR(50);
set @CategoryId ='124,125'
The failed message is:
Conversion failed when converting the nvarchar value ‘124,125’ to data
type int.
When I manually set the SQL where statement like below:
WHERE
StartRow = @StartRow
AND StartEnd = @StartEnd
AND CategoryId IN (124, 125)
It works.
How can I solve that converting problem?
You need to use dynamic SQL for this. So you would write
I hope this helps.