Ravindar, Biztalk Developer and Administrator

Just another BizTalk blog

split a comma seperated string in sql server

the variable AttributeItemID is the commma seperated string.

IF substring(@AttributeItemID, LEN(@AttributeItemID)-1,1)’,’
SET @AttributeItemID = @AttributeItemID + ‘,’ –add a comma to the end if it isn’t there

DECLARE @pos as int;
SET @pos=0;
DECLARE @splittedValue varchar(200);

WHILE charindex(‘,’,@AttributeItemID)>0
SET @splittedValue = cast(substring(@AttributeItemID,0, charindex(‘,’,@AttributeItemID))as int)

SET @AttributeItemID = substring(@AttributeItemID, charindex(‘,’,@AttributeItemID)+1, LEN(@AttributeItemID) – @pos) –remove the first item from the list


January 20, 2010 - Posted by | Sql Server

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: