Monday, November 15, 2010

Comma Delimited value in sql-server where condition

try to parse Comma Delimited value in sql-server in where condition, storing in a table and displaying values.
 
 
DECLARE
@sTemp VARCHAR(1000)

DECLARE

@psCSString VARCHAR(1000)

set

@psCSString='123,456,789,0123,dsdsd'

create

table #otTemp (fld varchar(20))

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)

--drop table #otTemp

--select @sTemp

END

select * from dshsjh in(

select * from #otTemp)

drop table #otTemp

No comments: