Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-04-15 : 04:16:56
|
| I have record declare @a varchar(max)set @a='Hi,Hello,Think'I need outputHi,Hell,ThinkRaghu' S |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-15 : 04:31:16
|
[code]CREATE FUNCTION dbo.fnParseList( @Delimiter CHAR, @Text varchar(max))RETURNS @Result TABLE (RowID SMALLINT IDENTITY(1, 1) PRIMARY KEY, Data VARCHAR(8000))ASBEGIN DECLARE @NextPos INT, @LastPos INT SELECT @NextPos = CHARINDEX(@Delimiter, @Text, 1), @LastPos = 0 WHILE @NextPos > 0 BEGIN INSERT @Result ( Data ) SELECT SUBSTRING(@Text, @LastPos + 1, @NextPos - @LastPos - 1) SELECT @LastPos = @NextPos, @NextPos = CHARINDEX(@Delimiter, @Text, @NextPos + 1) END IF @NextPos <= @LastPos INSERT @Result ( Data ) SELECT SUBSTRING(@Text, @LastPos + 1, DATALENGTH(@Text) - @LastPos) RETURNENDgodeclare @a varchar(max)set @a='Hi,Hello,Think'select Data from dbo.fnParseList(',',@a)[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-04-15 : 04:48:57
|
| Hey output is wrong I need Hi,Hello,Think,It ShowingHiHelloThinkRaghu' S |
 |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-04-15 : 04:50:48
|
| Ok I solved Thanks WebfredRaghu' S |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-15 : 04:51:51
|
select Data+',' from dbo.fnParseList(',',@a) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|