Take the 2-minute tour ×  I have a nvarchar value something like
'1,3,5,6', in my database table  But I want to use this in a
where condition, something like this where event_id IN (1,3,5,6)
How do I achieve that, How can I convert it and use in the IN of
a query  share|improve this question You need to use dynamic SQL
to achieve this. The good news is, there's no harm in this if
you follow best practice and check for SQL injection. Good luck!
–  user3914 Apr 17 '12 at 23:14 csv data in individual table
cells in evil. fix your schema. –  Joel Coel Apr 18 '12 at 17:09
2 Answers 2  up vote 1 down vote accepted  This must be done via
dynamic SQL. Something like this.  DECLARE @val nvarchar(20),
@sql nvarchar(100)  set @val = (select SomeColumn from
SomeTable)  SET @sql = 'SELECT * FROM AnotherTable WHERE Column3
IN (' + @val + ')'  exec (@sql) share|improve this answer Thank
you for the details but, I need to use a little complicated
query in the SET @sql section and it is not allowing me to
execute It is givi