|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, April 08, 2013 4:59 AM
Points: 196,
Visits: 79
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
|
|
Why 4 points for this question? I mean u can run this thing in SSMS and get the answer.
"Keep Trying"
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, April 08, 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..
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 6:56 AM
Points: 8,
Visits: 77
|
|
| XML using T-SQL would be less of a pain if it did allow variables
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, January 02, 2013 12:15 PM
Points: 1,443,
Visits: 711
|
|
| I think it's a pretty good question, would like to see more xml questions!
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: 2 days ago @ 1:47 PM
Points: 31,406,
Visits: 13,722
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:04 AM
Points: 1,342,
Visits: 1,946
|
|
Did this actually appear as intended?
SET @xml = ' '
I would have thought there should be something between the quotes.
Derek
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 8:26 AM
Points: 1,726,
Visits: 1,040
|
|
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.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
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."
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
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."
|
|
|
|