declare @ID as nvarchar(50)=''
SET @ID='1,2,3'
Select * from Orders_tbl where OrderId in (@ID)
Showing An error-
Msg 8114, Level 16, State 5, Line 3
Error converting data type nvarchar to numeric.
But working fine with direct values.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Sep 13, 2013, 8:21 AM
Jignesh TrivediPosted Sep 13, 2013, 5:43 AM
Agree with sanjeeb 's solution.
Alternative you can use split fubnction which inbuilt in SQL server 2008.
declare @ID as nvarchar(50)=''
SET @ID='1,2,3'
Select * from Orders_tbl where OrderId in (select value from fn_split(@ID,','))
hope this will help you.
Sanjeeb LenkaPosted Sep 13, 2013, 2:32 AM
try this:
declare @ID as nvarchar(50)=''
DECLARE @d VARCHAR(MAX)
SET @ID='1,2,3'
set @d = 'Select * from Orders_tbl where OrderId in('+@ID+')'
exec (@d)