Monday, November 15, 2010

Parsing string variable in Where clause with commas


string variable in Where clause with commas
 
DECLARE
@sTemp VARCHAR(1000)
DECLARE @psCSString VARCHAR(1000)
set @psCSString='dsdss,dsdd,sddsds,43443,dsdsd'
WHILE LEN(@psCSString) > 0
BEGIN
SET @sTemp = LEFT(@psCSString, ISNULL(NULLIF(CHARINDEX(',', @psCSString) - 1, -1),
LEN(@psCSString)))
SET @psCSString = SUBSTRING(@psCSString,ISNULL(NULLIF(CHARINDEX(',', @psCSString), 0),
LEN(@psCSString)) + 1, LEN(@psCSString))
-- INSERT INTO @otTemp VALUES (@sTemp)
select @sTemp
END

No comments: