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)
 Parsing Field Data Into Rows

Author  Topic 

gad
Starting Member

14 Posts

Posted - 2007-07-12 : 21:22:07
Hello,
I have a field that has the following data:

<li>Invalid email address.</li><li>Invalid zipcode.</li><li>Password is required.</li><li>

And, I'd like to parse this into rows separated by the "<li>"

Thanks!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-12 : 21:48:12
Use other char as delimiter if your data contain LF (char(10)) character


DECLARE @STR 		varchar(100),
@delimiter CHAR(1)

SELECT @STR = '<li>Invalid email address.</li><li>Invalid zipcode.</li><li>Password is required.</li><li>'
SELECT @delimiter = CHAR(10)

SELECT @STR = REPLACE(REPLACE(@STR, '</li>', @delimiter), '<li>', @delimiter)

SELECT *
FROM fnParseList(@delimiter, @STR)
-- fnParseList IS FROM http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033
WHERE Data <> ''

/*
RowID Data
------ ----------------------
2 Invalid email address.
4 Invalid zipcode.
6 Password is required.
*/



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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-13 : 00:05:21
Duplicate of http://sqlteam.com/forums/topic.asp?TOPIC_ID=86329

Madhivanan

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

- Advertisement -