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
 help

Author  Topic 

mani_1234
Starting Member

24 Posts

Posted - 2012-09-19 : 01:14:53
Hi ..
suppose i have input string as
input @str = 'a,b;c,d;e' where ; is the delimiter
now i want an output as
a(col1)
a,b
c,d
e
i want to do this with query only .and no function for it .

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-09-19 : 01:29:33
quote:
i want to do this with query only .and no function for it .

why ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mani_1234
Starting Member

24 Posts

Posted - 2012-09-19 : 01:48:49

its a kind of task that i have to perform ..
Go to Top of Page

joshua_caleb
Starting Member

3 Posts

Posted - 2012-09-19 : 02:24:59
Hi mani_1234,

Assuming you want to create a temporary table and insert the split values into it, you can use these queries.

INSERT INTO tblTemp
(Col1)
SELECT PARSENAME(REPLACE('a,b;c,d;e', ';', '.'), 3) AS Expr1
INSERT INTO tblTemp
(Col1)
SELECT PARSENAME(REPLACE('a,b;c,d;e', ';', '.'), 2) AS Expr1

INSERT INTO tblTemp
(Col1)
SELECT PARSENAME(REPLACE('a,b;c,d;e', ';', '.'), 1) AS Expr1


select * from tblTemp will return you the output.

Col1

a,b
c,d
e

Note:ParseName takes a number as it's second argument, and that number specifies which segment of the string to return (working from the end of the string to its beginning).


Josh
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-09-19 : 02:32:11
quote:
Originally posted by mani_1234


its a kind of task that i have to perform ..



in case you have change your mind and allow to use function, you can take a look at http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -