Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

XML XQuery problem Expand / Collapse
Author
Message
Posted Wednesday, March 11, 2009 11:23 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, April 8, 2013 4:59 AM
Points: 196, Visits: 79
Comments posted to this topic are about the item XML XQuery problem
Post #673946
Posted Thursday, March 12, 2009 2:18 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 8:08 AM
Points: 2,365, Visits: 1,846
Why 4 points for this question? I mean u can run this thing in SSMS and get the answer.

"Keep Trying"
Post #673993
Posted Thursday, March 12, 2009 3:22 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, April 8, 2013 4:59 AM
Points: 196, Visits: 79
Do not now - I'am only author of this question, others are responsible for give a score..
Post #674027
Posted Thursday, March 12, 2009 3:30 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, December 4, 2014 4:11 AM
Points: 550, Visits: 127
XML using T-SQL would be less of a pain if it did allow variables
Post #674031
Posted Thursday, March 12, 2009 5:06 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Wednesday, January 2, 2013 12:15 PM
Points: 1,443, Visits: 711
I think it's a pretty good question, would like to see more xml questions!
Post #674076
Posted Thursday, March 12, 2009 8:46 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 3:11 PM
Points: 31,368, Visits: 15,837
If you want to run it in SSMS and get the answer, that's up to you. However that kind of defeats the purpose of the questions. You should make an attempt to answer the question without running it.

Think about it, if someone asked you this in an interview, would you answer it or say, "I can't do it without SSMS?"







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #674318
Posted Thursday, March 12, 2009 10:39 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, December 11, 2014 3:10 AM
Points: 1,274, Visits: 1,987
Did this actually appear as intended?
SET @xml = 
'
'

I would have thought there should be something between the quotes.


Derek
Post #674448
Posted Thursday, March 12, 2009 11:28 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, November 24, 2014 9:31 AM
Points: 1,736, Visits: 1,072
Could someone give me a code example of this that does work. I tried:

DECLARE @xml xml;
DECLARE @expression nvarchar(128);
SET @xml =
'<books>
<book price=''31'' name=''SQL Server Central'' Author=''Steve Jones''/>
</books>';

--SET @expression = '/books/book/@price[text()=31]';


IF @xml.exist('/books/book/@price[text()=31]') =1
SELECT
T.value('./@price[1]','int'),
T.value('./@name[1]','nvarchar(32)'),
T.value('./@Author[1]','nvarchar(32)')
FROM @xml.nodes('/books/book') AS T(T);

and I get the error:

XQuery [exist()]: Result of 'text()' expression is statically 'empty'

So I replace the XPath expression with:

/books/book/@price=31

and it works.

I don't use Xml and XPath every day, but I understand most of the basic concepts. What should the Xml look like in order to use the original XPath expression? The '@price' means an attribute and 'text()' all the text within a node. To me, the XPath expression is invalid or just doesn't make sense.

P.S.
Did the author just do the same thing I did and forget to escape out the '<' with '& lt;' in the Xml string when writing and posting the question?

P.P.S
I can't get an escaped ampersand followed by 'lt;', as in above to show up in these forums without manually putting that space between them.



Post #674498
Posted Thursday, March 12, 2009 1:46 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, December 4, 2014 7:52 AM
Points: 9,294, Visits: 9,495
Derek Dongray (3/12/2009)
Did this actually appear as intended?
SET @xml = 
'
'

I would have thought there should be something between the quotes.

Actually, I think that was the toughest part of this question. I spent 5 minutes thinking about whether or not this was another case of the XML getting eaten by this site before I risked the 4 points by trying to answer it! (maybe that's why it 4 points? :) )


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #674667
Posted Thursday, March 12, 2009 1:53 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, December 4, 2014 7:52 AM
Points: 9,294, Visits: 9,495
Steve Jones - Editor (3/12/2009)
If you want to run it in SSMS and get the answer, that's up to you. However that kind of defeats the purpose of the questions. You should make an attempt to answer the question without running it.

Think about it, if someone asked you this in an interview, would you answer it or say, "I can't do it without SSMS?"

FWIW, I do not think that questions of the form "What would you get if you ran this in SSMS" are the best choice, either here or in an interview.

In fact I would never ask a question like that in an interview unless I wanted them to say "Try it and see." I already have a resource that can tell me that both faster and more accurately: SSMS.

Now a much more useful question form, both in interviews and for SSC (IMHO), is "When I run this in SSMS, I get this. WHY?" You just have to make sure that there is a definitive and deterministic answer (which admittedly takes some work to get right).


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #674675
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse