January 27, 2014 at 8:50 pm
Comments posted to this topic are about the item value() Method (xml Data Type)
January 27, 2014 at 11:20 pm
mikael,
Learnt something new today, thanks
I tried with the below solution to get the value from item code
DECLARE @XML as xml='
<root>
<item>1987</item>
<item>1654</item>
<item>1321</item>
</root>';
select @XML.value('/root[1]', 'nvarchar(15)') -- this is returning value as '198716541321'
select @XML.value('/root[1]', 'int') -- this is throwing error
January 28, 2014 at 12:18 am
Interesting question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 28, 2014 at 1:30 am
This was removed by the editor as SPAM
January 28, 2014 at 5:42 am
a ha, Finally got my coffee first before answering the question. Studied the question and played around a little. Learned too, thats a great way to start the day off.
January 28, 2014 at 6:28 am
Nice questions, thanks. I don't use XML often, but when I do, I use it slowly. 😉
January 28, 2014 at 7:20 am
Ed Wagner (1/28/2014)
Nice questions, thanks. I don't use XML often, but when I do, I use it slowly. 😉
+1 I really liked this question. I don't use XML in my current work. But, this question prompted me to do some exploring. Thanks Mikael!
[font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
Connect to me on LinkedIn
January 28, 2014 at 8:15 am
I got the right answer but for the wrong reason--I assumed the XQuery expression would return 3 separate values, which would break the requirement for value() to return only one. What can I say, I don't ever use XML and the XQuery documentation is not the best-written I've ever come across! 🙂
January 28, 2014 at 9:32 am
great question.
had to do a little research.. but worth it.
Thanks Mikael.
January 28, 2014 at 12:25 pm
I had it right, for the wrong reason. I expected an error because the first "root" node contains an XML fragment with multiple nodes, not a singleton. So I expected an error to that effect. I had not expected SQL Server to simply concatenate all values and act is if they are one.
If the question had used bigint instead of int, I would have gotten it wrong.
January 28, 2014 at 9:29 pm
Thanks for this nice one, Mikael!
January 30, 2014 at 6:58 am
Since the beginning I had an issue for understanding XML queries & data type as well, maybe because of incomplete, insufficient documentation for it.
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
January 30, 2014 at 6:59 am
Hugo Kornelis (1/28/2014)
I had it right, for the wrong reason. I expected an error because the first "root" node contains an XML fragment with multiple nodes, not a singleton. So I expected an error to that effect. I had not expected SQL Server to simply concatenate all values and act is if they are one.If the question had used bigint instead of int, I would have gotten it wrong.
+ 2 🙂
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
February 3, 2014 at 1:52 pm
Thomas Abraham (1/28/2014)
Ed Wagner (1/28/2014)
Nice questions, thanks. I don't use XML often, but when I do, I use it slowly. 😉+1 I really liked this question. I don't use XML in my current work. But, this question prompted me to do some exploring. Thanks Mikael!
+1
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
February 4, 2014 at 10:55 pm
Very interesting question. 🙂
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply