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.
| Author |
Topic |
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-05-24 : 11:17:55
|
A while back I believe peso posted a great trick when concatenating values using for XML.The way it worked was when you did a query like soselect myfield as [text()]from mytable afor xml path('')I can not find anywhere why text() removes the xml tags in BOL, and whether that is it's intended use or if this was just a trick that someone found out where it just works.Can someone please point me to why this works. Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-05-24 : 11:30:45
|
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254There are other methods to use besides text() trick.One of the other methods also deals with entitization! E 12°55'05.63"N 56°04'39.26" |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2009-05-24 : 11:41:24
|
yeah bol really, really, really, really, really, really, really, really SUX when searching for xml related stuff.text() is used to select the text node if there are nodes that are not text.look here and search for text()http://msdn.microsoft.com/en-us/library/ms345122.aspxlook at this example:-- concats data after selecting only text data of the rowSELECT City AS [text()]FROM Person.AddressFOR XML PATH('')-- concats data in normal xml style, creates an xml item for each row dataSELECT CityFROM Person.AddressFOR XML PATH('')-- we add the + ',' and it concats text data from the rowsSELECT City +',' AS [text()]FROM Person.AddressFOR XML PATH('')-- same as above. it just implicitly uses [text()] to concat row dataSELECT City + ',' FROM Person.AddressFOR XML PATH('')___________________________________________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.5 out! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-05-24 : 12:09:33
|
Found it...AS [text()]AS [processing-instruction(query)] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-05-24 : 12:20:08
|
Thanks, that ansers it! Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
|
|
|
|
|