Consider the following example:
Declare @string Varchar(100),@delimiter CHAR(1)
Set @string = 'See if you can you split this'
set @delimiter = ' '
Declare @Xml Xml
Select @Xml = Cast('<d>' +
Replace(@string, @Delimiter,'</d><d>') + '</d>' As Xml )
SELECT T.split.value('.', 'nvarchar(max)') AS data
FROM @XML.nodes('/d') T (split)
In the above example the variable @Xml is of type xml. It concatenates the
original string by replacing a space with </d><d> so that each word will be surrounded
by <d> and </d>. The string is split by identifying the elements within <d> and </d>.
original string by replacing a space with </d><d> so that each word will be surrounded
by <d> and </d>. The string is split by identifying the elements within <d> and </d>.
OUTPUT
Did you like this post?
|
|
|
||
|
|
|
|
|
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |




comments
0 Responses to "SQL Server: String operations in XML document"Post a Comment