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 Programming
 comma separate ???

Author  Topic 

sweet_777
Starting Member

16 Posts

Posted - 2010-10-21 : 09:21:46
HI all,

in my O/P IS LIKE THIS: 1A2B3C

HOW TO SPLIT COMMA SEPARATED VALUE

EX:1,A,2,B,3,C

if any body knows please let me know

Thanks & Regards
Sweet_77

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-21 : 09:58:18
You are always asking for things that should better not be done in SQL Server.
I am curious about what all that trash should be for.
Also you are never giving response about given solutions if they work for you or not.

Hm...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Devart
Posting Yak Master

102 Posts

Posted - 2010-10-21 : 10:02:02
Hello,

You can create scalar-valued function and use it.
For example:

CREATE FUNCTION f_str_separator(
@string varchar(8000),@separator varchar(10))
RETURNS varchar(8000)
AS
BEGIN
DECLARE @len int
DECLARE @i int
DECLARE @new varchar(8000)
SET @i=1
SET @len = datalength(@string)
SET @new = ''
WHILE @i<=@len
BEGIN
SET @new = @new+right(left(@string,@i),1)+@separator
SET @i=@i+1
END
RETURN @new
END

GO

SELECT dbo.f_str_separator('1A2B3C',',')

OR

SELECT
dbo.f_str_separator(<string_valued_field>,',')
FROM <your_table_name>

Best regards,

Devart,
SQL Server Tools:
dbForge Schema Compare
dbForge Data Compare
dbForge Query Builder
Go to Top of Page
   

- Advertisement -