TSQL- XQuery

  • Comments posted to this topic are about the item TSQL- XQuery

    Pramod
    SQL Server DBA | MCSE SQL Server 2012/2014

    in.linkedin.com/in/pramodsingla/
    http://pramodsingla.wordpress.com/

  • Tsk tsk, first question of the week, and it's about XQuery (ugh). And even a trick question (double ugh).

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen Verbeeck (7/28/2013)


    Tsk tsk, first question of the week, and it's about XQuery (ugh). And even a trick question (double ugh).

    I second those "ugh"'s

    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

  • Nice one....+1

  • SQLRNNR (7/28/2013)


    Koen Verbeeck (7/28/2013)


    Tsk tsk, first question of the week, and it's about XQuery (ugh). And even a trick question (double ugh).

    I second those "ugh"'s

    Yes lot of "ughs"....

  • Anipaul (7/28/2013)


    SQLRNNR (7/28/2013)


    Koen Verbeeck (7/28/2013)


    Tsk tsk, first question of the week, and it's about XQuery (ugh). And even a trick question (double ugh).

    I second those "ugh"'s

    Yes lot of "ughs"....

    +1 ๐Ÿ™‚

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!

  • This was removed by the editor as SPAM

  • Koen Verbeeck (7/28/2013)


    Tsk tsk, first question of the week, and it's about XQuery (ugh). And even a trick question (double ugh).

    It's not really about XQuery though, it's a trick question which doesn't test anything other than how well you can read things on a Monday morning ๐Ÿ˜‰

  • I like the question. I don't think it's a trick question - many people here are so used to using case insensitive collations (stupid defaults!!!) that they can and will be caught by this XML feature. Probably numerous times. I know I have, it's probably the main reason I got it right.

    And the second good thing about the question is that it also makes you think about what would have been returned if the case had been correct. I know I was not really sure of that (I'm far from an XML expert!), so I was happy that the lower-/uppercase thing gave me a guaranteed point, and the rest of the question gave me the opportunity to play with the code and see what happens if I change the case - so this has also taught me something about the XQuery data function. (And if I just happen to stumble on it again within a week or so, it might even stick this time).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Hugo Kornelis (7/29/2013)


    I like the question. I don't think it's a trick question - many people here are so used to using case insensitive collations (stupid defaults!!!) that they can and will be caught by this XML feature. Probably numerous times. I know I have, it's probably the main reason I got it right.

    And the second good thing about the question is that it also makes you think about what would have been returned if the case had been correct. I know I was not really sure of that (I'm far from an XML expert!), so I was happy that the lower-/uppercase thing gave me a guaranteed point, and the rest of the question gave me the opportunity to play with the code and see what happens if I change the case - so this has also taught me something about the XQuery data function. (And if I just happen to stumble on it again within a week or so, it might even stick this time).

    +1 ๐Ÿ™‚

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • I also don't see the trick, but even if "data" has been added properly it would (or should) still have given an error because "<a>1<c>3</c><d>4</d></a>" is not valid XML: <a> is obviously a complex element because it contains <c> and <d>, so it can't contain "1".

  • matthew.flower (7/29/2013)


    <a> is obviously a complex element because it contains <c> and <d>, so it can't contain "1".

    Where did you get that idea from? It's perfectly valid.

  • I answered this question yesterday (as often happens Monday's question was available on Sunday) and didn't see anything in it that needed comment, Then today here piles of comments calling it a trick question. And one sensible comment:

    Hugo Kornelis (7/29/2013)


    I like the question. I don't think it's a trick question

    I agree, it's not. There are things which are case sensitive, and this is one of them so there's no trick here.

    many people here are so used to using case insensitive collations (stupid defaults!!!) that they can and will be caught by this XML feature.

    Some of us expect case insensitivity as the norm, but know that we have to be aware when something is case sensitive. So we don't get caught - at least not after the first time. And when its associated with something else pretty awful - two pretty awful things here: XQuery and XML - and especially when the case sensitivity is itself awful because it's utterly pointless, so that we have three pretty awful things in conjunction, it is memorable because of it's sheer awfulness.

    Probably numerous times.

    No, just once.

    And the second good thing about the question is that it also makes you think about what would have been returned if the case had been correct. I know I was not really sure of that (I'm far from an XML expert!), so I was happy that the lower-/uppercase thing gave me a guaranteed point, and the rest of the question gave me the opportunity to play with the code and see what happens if I change the case - so this has also taught me something about the XQuery data function. (And if I just happen to stumble on it again within a week or so, it might even stick this time).

    I have some vague recollection that "data" means do a top-start depth-first left-to-right traverse of the subtree consisting of the designated node and all its descendants, starting with no data and at each node concatenating the data of that node (if any) to the data accumulated so far (concatenating it to an empty string of data if none has yet been accumulated) and returning the accumulated data with no indication of where the boundaries between the data of one node and another node might be (i.e. totally devoid of structural information). That might actually be wrong, but I don't care because if I need to know I can either play (if I have a SQL Server instance I can play with handy) or look it up (if I have internet access handy) and it's pretty unlikely that I would need to know in any situation where either of those facilities was absent, let alone both. But it's probably about right as it means that if "data" had been spelt right the two XQuerys would have produced the result given as the first wrong answer option, which would make that option a good distractor - another reason not to dislike the question despite its horrible subject matter.

    Tom

  • Toreador (7/29/2013)


    matthew.flower (7/29/2013)


    <a> is obviously a complex element because it contains <c> and <d>, so it can't contain "1".

    Where did you get that idea from? It's perfectly valid.

    +1000.

    XML would be pretty useless if non-leaf nodes couldn't contain data. (Actually, it's already rather more useless than many of those who misuse it tend to think :-D.)

    It's name, eXtended Mark-up Language, makes it pretty clear that it has to be able to put mark-up at any point in the structure it's annotating. So I guess that for something where annotation of non-leaf constructs is required XML without data at non-leaf nodes would have to describe the whole structure at the leaf level, which could be orders of magnitude more clumsy and verbose than XML is. I wonder if the strange idea expressed by Matthew is widespread? If so it might account for some of the really bad XML that can be found out in the wild.

    Tom

  • L' Eomot Inversรฉ (7/29/2013)


    if I need to know I can either play (if I have a SQL Server instance I can play with handy) or look it up (if I have internet access handy)

    True. The reason I still think it's good to know is not for the scenario where you get someone else's code and are wondering what the data function does (I would handle that exactly the same way you do), but for the scenario where you are given a task that might benefit from this function. Admittedly, the behaviour of the function is weird enough that it's hard to think of a realistic use case - but if you do run into one and don't remember that such a function exist, you might find yourself working very hard to reproduce this behavior using other XQuery expressions. Whereas in that situation, if you do happen to know that there is a function to do just that (even if you perhaps forgot the name and have to google for it), you'll save a lot of time and effort.

    I share your antipathy (or should I say hatred?) of XML and XQuery. But matter of fact is, it is a part of the product I work with, and it's my professional responsibility to ensure I have at least sufficient working knowledge to handle things if they come up.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic. Login to reply