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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 12, 2013, 10:32 PM EDT
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)
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 13, 2013, 1:43 AM EDT
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.
Suthish NairRank #92 · 22.8K reputationPosted Sep 13, 2013, 4:21 AM EDT