Hi Pinak,
your query
select * from table where Id in ('7,3,120')
returns error, because it is comparing integer column with varchar value ie. '7,3,120'.
Sql server engine tries to parse the varchar value into integer. Because of ',', it gives error.
Following query will return the result set ...
select * from table where Id in ('7','3','120')
But still it is static.To make it dynamic, you need to split the varchar value.
Following query helps to get the result set with out getting any error.
DECLARE @ids VARCHAR(100) = '7,3,120';
DECLARE @Xparam XML;
SELECT @Xparam = CAST('<i>' + REPLACE(@ids,',','</i><i>') + '</i>' AS XML)
SELECT * FROM Yourtable WHERE Id IN (SELECT x.i.value('.','INT') FROM @Xparam.nodes('//i') x(i))
Thank you..