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
|
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 |
|||||
|
|
This must be done via dynamic SQL. Something like this.
|
|||||||
|
|
I am able to fig-out and fix it not sure why but the issue is The query is not executing if I write SET @sql = but its working when I change to EXEC ('SELECT TOP 20 a.aa, a.bb, a.cc, a.dd, c.pp, a.ee FROM a LEFT OUTER JOIN b ON a.ff= b.ff LEFT OUTER JOIN c ON a.gg= c.gg WHERE len(a.aa) > 0 AND b.aa IN ('+@val +') AND a.xx= 1') Thank you |
||||
|
|