SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using XML to Enhance the Performance of String Manipulations


Using XML to Enhance the Performance of String Manipulations

Author
Message
WayneS
WayneS
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9932 Visits: 10573
Comments posted to this topic are about the item Using XML to Enhance the Performance of String Manipulations

Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings

WayneS
WayneS
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9932 Visits: 10573
Hey all...

I don't know how it happened, but the code in the article is missing some spaces from what I submitted. They should be pretty obvious where that is, but if you are having problems let me know and I'll post how it should be (or get Steve or someone to add them to the article).

The biggest offenders:
space needed between "use" and "AdventureWorks"
space needed between "set" / "select" / "declare" / "print" / "if" and the rest of the command.
space needed between "FOR" and "XML"
space needed between "XML" and "PATH"

Wayne

Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings

JPJ
JPJ
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 30
I agree with you wayne.

I have a small issue in addition to that, this line gave me error:

select @MyXMLString = @MyXMLString +
' '+ AccountNumber +
' '


This is the error:

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'AccountNumber'.

Any idea?
Philippe Cand
Philippe Cand
SSC-Enthusiastic
SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)

Group: General Forum Members
Points: 114 Visits: 294
Great article, this may solve the problem I had with this code that would have been considerably faster than Coalesce.

-- create list to pivot hist data
SELECT @DistList =
COALESCE(@DistList + ',[', '[') +
CAST(Dist AS VarCHAR(85)) + ']'
FROM (
SELECT top 1000 Disty
FROM @t1
Order by Disty
) t(Dist)

-- try for XML to speed up the coalesce -- may bug on Shangai P&S
--Select @DistList = (
--SELECT Disty + ', ' As [text()]
-- FROM @t1
-- ORDER BY Disty
-- FOR XML PATH('')
--)
--Set @DistList = LEFT(@DistList, Len (@DistList) -1)



BI Guy
Anipaul
Anipaul
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7353 Visits: 1407
Nice Article...Smile



anil_mootha
anil_mootha
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 8
Hi,
Why would you prefer to build XML strings manually when you can do it with FOR XML statement.
The very purpose of FOR XML statement would be void otherwise.

Thanks and regards
Anil
Samuel Vella
Samuel Vella
SSC Eights!
SSC Eights! (833 reputation)SSC Eights! (833 reputation)SSC Eights! (833 reputation)SSC Eights! (833 reputation)SSC Eights! (833 reputation)SSC Eights! (833 reputation)SSC Eights! (833 reputation)SSC Eights! (833 reputation)

Group: General Forum Members
Points: 833 Visits: 2144
WayneS (8/19/2008)
Hey all...

I don't know how it happened, but the code in the article is missing some spaces from what I submitted.


Seems to be happening on other articles too, I noticed it on this one yesterday:
http://www.sqlservercentral.com/articles/Integration+Services/63623/

although that one also suffers from the code sections being strangely fragmented
SuperDBA-207096
SuperDBA-207096
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1961 Visits: 711
Excellent article... thanks!
Paul DB
Paul DB
SSC-Enthusiastic
SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)

Group: General Forum Members
Points: 130 Visits: 258
anil_mootha (8/20/2008)
Hi,
Why would you prefer to build XML strings manually when you can do it with FOR XML statement.
The very purpose of FOR XML statement would be void otherwise.

Thanks and regards
Anil


I'm also interested in knowing the answer to Anil's question. Have a great day. Cool

Paul DB
WayneS
WayneS
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9932 Visits: 10573
JPJ (8/19/2008)
I agree with you wayne.

I have a small issue in addition to that, this line gave me error:

select @MyXMLString = @MyXMLString +
' '+ AccountNumber +
' '


This is the error:

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'AccountNumber'.

Any idea?


(I do wish that this site's forum board would support the display of XML tags easier!)

For that select command, there are two extraneous quote marks. The first is on the second line, after the "Row" xml tag immediately prior to the "AccountNumber" tag. The second is on the third line, immediately after the backslash character and immediately prior to the "AccountNumber" tag.

So, it should look like:
select @MyXMLString = @MyXMLString +
'<Row><AccountNumber>'+ AccountNumber +
'</AccountNumber></Row>'

Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search