May 29, 2009 at 9:05 am
I was trying to use xquery to extract the data from a xml field so that i could use that data in another field.
XML:
I was trying to select it like this per msdn
SELECT Extension.Value('Data((/doc//Extension/Length)[1]','Nvarchar(max)')
FROM [dbo].[Test]
This is the message.
Msg 227, Level 15, State 1, Line 1
"Value" is not a valid function, property, or field.
Any help would be great
May 29, 2009 at 9:15 am
XQuery is case-sensitive.
"Value" needs to be "value" (all lower-case), "Extension" needs to be "EXTENSION" in the value query, and so on.
Here's a working version:
select cast('1.5' as XML) as Extension
into #T;
--
select Extension.value('(/EXTENSION/.)[1]','Nvarchar(max)')
from #T;
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
May 29, 2009 at 9:24 am
X-Query is case sensitive, so all the methods and the data elements used in the xml must match with that used in the methods. For e.g.
The method "Value" should "value" and the xml element "Extension" should be "extension" and also the "Data" method is not a valid method (i suppose).
The working code for the sample:
DECLARE @SomeXML XML
SET @SomeXML = '
1.5
'
SELECT@SomeXML.value('(/extension/length)[1]','Nvarchar(max)')
Edit:
Just a little too late to post!!!:-)
Gus, does you mean the element "Extension" should be changed to "extension" (same as in xml) and not to "EXTENSION"?
--Ramesh
May 29, 2009 at 10:05 am
Awesome thanks. Works great.
May 29, 2009 at 11:14 am
Ramesh (5/29/2009)
X-Query is case sensitive, so all the methods and the data elements used in the xml must match with that used in the methods. For e.g.The method "Value" should "value" and the xml element "Extension" should be "extension" and also the "Data" method is not a valid method (i suppose).
The working code for the sample:
DECLARE @SomeXML XML
SET @SomeXML = '
1.5
'
SELECT@SomeXML.value('(/extension/length)[1]','Nvarchar(max)')
Edit:
Just a little too late to post!!!:-)
Gus, does you mean the element "Extension" should be changed to "extension" (same as in xml) and not to "EXTENSION"?
In the OP's example XML, the elements were uppercase on my screen. That might be something with the scripts on the page, but it's how they show on my screen, so it's what I used.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
May 29, 2009 at 12:32 pm
GSquared (5/29/2009)
In the OP's example XML, the elements were uppercase on my screen. That might be something with the scripts on the page, but it's how they show on my screen, so it's what I used.
As stated by Flo in another thread it's caused by the java-script client-side render engine.
Easiest way to find the original xml format is using the quote button - it'll show the original xml (learned from Flo again...)
May 29, 2009 at 6:14 pm
Heh... "XML is case sensitive"... one more reason for me to keep it out of my databases. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
May 30, 2009 at 1:42 am
GSquared (5/29/2009)
In the OP's example XML, the elements were uppercase on my screen. That might be something with the scripts on the page, but it's how they show on my screen, so it's what I used.
I knew there must be something I am missing when I saw your post. Never seen such rendering on my machine (Or may be I never noticed it), looks strange to me.
--Ramesh
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply