How to split the data based on some seperator - Easy and Simple Logic

PandianS
Posted by PandianS under Sql Server category on | Points: 40 | Views : 2361
We just want to split the data based on some particular seperator (Here we have used comma(,) as a seperator)

Yes. We may have different logics..... But, which one is simplest way ?
Declare @Data	Varchar(1000),
@Seperator Varchar(2)
Select @Data = '1,200,310,41', @Seperator=','
Select @Data = 'Select ' + REPLACE(@Data,@Seperator, CHAR(10) + 'Union All' + Char(10)+ 'Select ')
EXEC(@Data)
1
200
310
41
Note: You can change this script for further requirement/logics...

Comments or Responses

Posted by: T.saravanan on: 7/10/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi PandianS,

Its really nice info.

Login to post response