Use delimited field value as 'IN clause'
Posted on 2004-08-09
I have a table with a field set up as nvarchar (255), an example of data in this field is '4,5,6,7,11,12,13' (without the single quotes) those values match up to keys in a different table. What i need to do (using a stored proceedure) is select the keyed records. This is what i thought would work, but does not:
DECLARE @UID int
SET @UID = 5
SELECT * FROM SKIP_WebSites WHERE SiteID IN (SELECT SkipSites FROM Users WHERE ID = @UID)
The error i get is:
Syntax error converting the nvarchar value '4,5,6,7,11,12,13' to a column of data type int.
I suppose my error was thinking it could be that simple, any help on how to achieve this ?