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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 fn to split concatenated and delimited string

Author  Topic 

techytechy
Starting Member

1 Post

Posted - 2010-01-12 : 09:47:02
Hi guys,

I am using sql server 2005
Need a function to split concatenated and delimited string into seperate columns

Input to the function is one string like:

Fn('code1-Region1, code1-Region2, code2-region1')

in the above Concatenation is '-' and delimiter is ','

Need output into two tables like:

OutputTable1
--------------------
codecol
-----------
code1
code2
....
....
---------------------

OutputTable2
----------------------
Regioncol
-----------
Region1
Region2
....
....
-----------------------

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-12 : 09:48:31
Search for Split function in this forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 10:24:35
[code]
INSERT INTO OutputTable1
SELECT PARSENAME(REPLACE(f.Val,'-','.'),2)
FROM dbo.ParseValues(@YourString,',') f
ORDER BY f.ID

INSERT INTO OutputTable2
SELECT PARSENAME(REPLACE(f.Val,'-','.'),1)
FROM dbo.ParseValues(@YourString,',') f
ORDER BY f.ID

Parsevalues can be found here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=115544

[/code]
Go to Top of Page
   

- Advertisement -