Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


value() Method (xml Data Type)


value() Method (xml Data Type)

Author
Message
Mikael Eriksson SE
Mikael Eriksson SE
SSChasing Mays
SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)

Group: General Forum Members
Points: 649 Visits: 959
Comments posted to this topic are about the item value() Method (xml Data Type)



pmadhavapeddi22
pmadhavapeddi22
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1356 Visits: 1867
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


Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18961 Visits: 13250
Interesting question, thanks.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCertifiable
SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)

Group: General Forum Members
Points: 6416 Visits: 7194
Good question, thanks.
I've said it before and will say it again, the documentation regarding Xquery is incomplete...

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Michael_Garrison
Michael_Garrison
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1254 Visits: 2754
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.
Ed Wagner
Ed Wagner
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11489 Visits: 9795
Nice questions, thanks. I don't use XML often, but when I do, I use it slowly. ;-)


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Thomas Abraham
Thomas Abraham
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2433 Visits: 2255
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!

Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
paul.knibbs
paul.knibbs
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2132 Visits: 6223
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! :-)
pchirags
pchirags
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2255 Visits: 615
great question.
had to do a little research.. but worth it.
Thanks Mikael.
Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8848 Visits: 11738
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.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
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