April 14, 2010 at 3:30 pm
ychen 55059 (4/14/2010)
Thank you so much. That works beautifully.I'm not familiar with XML. Could you point me to some additional resources so that I can understand what your code actually does?
Thanks again.
You can start here.
http://msdn.microsoft.com/en-us/library/ms190922.aspx
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 14, 2010 at 3:32 pm
Here is a SQLMagazine article on the topic.
http://www.sqlmag.com/article/tsql3/nifty-ways-to-use-for-xml-path-concatenation.aspx
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 14, 2010 at 3:35 pm
THANK YOU!!
April 14, 2010 at 3:37 pm
You're welcome.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 14, 2010 at 4:54 pm
Maybe this link will be of some help, too:
http://www.sqlservercentral.com/Forums/Topic679572-338-2.aspx
Barry did a great job explaining how the STUFF ... FOR XML PATH actually works.
April 14, 2010 at 5:22 pm
Yes, the examples were very helpful indeed. Thank you!
April 15, 2010 at 9:34 am
First, glad we could help.
Second, I knew others would provide you with links that would help you understand the FOR XML. Thanks to you all as well.
April 15, 2010 at 10:02 am
Here is another excellent article on Stuff and For XML
http://www.sqlservercentral.com/articles/Test+Data/61572/
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
December 19, 2011 at 1:14 am
I am not sure what the execution times for the following query would be as I have not implemented any hints or indexes on the temp table created however probably you can give this a shot (The only time lag here would actually be the replace statements as mentioned below.... try it out an let me know :w00t: )
select reportid,replace(replace(Val,'<User2>',''),'</User2>','')
from
(select distinct a.reportid,
--(select top 1 User2 from #tbl b where b.reportid=a.reportid) as Test,
(select distinct User2+' ' from #tbl c where c.reportid = a.reportid FOR XML PATH('')) as Val
from #tbl a) x
This would give you the following result:-
July 20, 2013 at 9:37 am
CTE, temp table with index or table variable... which one is more performant?
July 20, 2013 at 4:39 pm
rahulraghvn (7/20/2013)
CTE, temp table with index or table variable... which one is more performant?
None of the above. Use the XML method that was posted.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 22, 2013 at 8:56 pm
LutzM (4/14/2010)
Maybe this link will be of some help, too:http://www.sqlservercentral.com/Forums/Topic679572-338-2.aspx
Barry did a great job explaining how the STUFF ... FOR XML PATH actually works.
SQLRNNR (4/15/2010)
Here is another excellent article on Stuff and For XML
Innocently but blatantly hijacking this thread, it is coincidental that I was recently searching for an article on FOR XML PATH, running across both of these excellent explanations.
However I was looking for a bit more. Specifically, I'm wondering if anyone knows of an article that not only explains how it works and also gives examples that adds the special handling for when the content of the column contains one of the restricted characters? I recently saw someone post a performance comparison of the "standard" approach next to the one with special character handling, and I can't even find that at the moment.
It seems that all of the ones I've run across either show it without special character handling or with, and only Jeff's examines the performance.
If the article explained performance as well it would be a bonus. Thanks.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
Viewing 12 posts - 16 through 26 (of 26 total)
You must be logged in to reply to this topic. Login to reply