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.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 split function

Author  Topic 

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-10-01 : 13:29:55
My output is 1,2,3,4,5,6
But my need is
1
2
3
4
5
6
What can I do ?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-10-01 : 13:33:17
Take your pick:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=66911
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-01 : 15:49:11
[code]
CREATE FUNCTION dbo.udf_Table(@ParmList varchar(8000), @Delim varchar(20))
RETURNS @table TABLE
(Parameter varchar(255))
AS

BEGIN
-- SELECT @ParmList = 'a,b,c', @Delim = ','
DECLARE @x int, @Parameter varchar(255)

WHILE CHARINDEX(@Delim, @ParmList)-1 > 0
BEGIN
INSERT INTO @table(Parameter) SELECT SUBSTRING(@ParmList,1,CHARINDEX(@Delim, @ParmList)-1)
SELECT @ParmList = SUBSTRING(@ParmList,CHARINDEX(@Delim, @ParmList)+1, LEN(@ParmList)-CHARINDEX(@Delim,@ParmList))
END
INSERT INTO @table(Parameter) SELECT @ParmList
RETURN
END
GO
[/code]


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page
   

- Advertisement -