The Attribute

  • What a mess. The correct answer would be none of these, since only one of them is a query and it returns NULL. And when this is corrected so that all four are queries, the 4th returns the correct value as well as the third - the claim in the explanation that it returns additional values seems to be incorrect (it doesn't return anything other han the name on my SQL Server 2016 installation, because the query in the question was

    select @x.value( '(teams/team[@name="Broncos"]/players/player/name)[1]','varchar(250)' ).

    Given the choice between the two correct answers, I picked 4 because it's a marginally more reasonable query - the team part of the search is based on data rather than knowledge of position in some list.

    edit: looking at the website now the query (as listed in the results so far) seems to have changed so as to match the explanation.

    Tom

  • I've added a SELECT to all answers.

    However, in retesting, I get these answers for the four respectively (cut and paste the code in SSMS 2016).

    NULL

    Dak Prescott

    Trevor Siemian

    TrevorSiemianNorthWestern2

    Tom, not sure why the fourth one doesn't return more data for you. This query

    SELECT @x.value('(teams/team[@name="Broncos"]/players/player)[1]','varchar(250)')

    Should return all values for elements in the player node.

  • Steve Jones - SSC Editor (10/14/2016)


    I've added a SELECT to all answers.

    However, in retesting, I get these answers for the four respectively (cut and paste the code in SSMS 2016).

    NULL

    Dak Prescott

    Trevor Siemian

    TrevorSiemianNorthWestern2

    Tom, not sure why the fourth one doesn't return more data for you. This query

    SELECT @x.value('(teams/team[@name="Broncos"]/players/player)[1]','varchar(250)')

    Should return all values for elements in the player node.

    I guess I must have copied it wrongly when I scribbled the four quries down to look at them on the bus (I need thinking time with any question involving XML) Of course then when I found it didn't work and saw the explanation and ran it I copied it from my scribbled note, not from the website, and it had "/name" in it. Stupid of me.

    Tom

  • My answer would be "None of the above" because I don't want people to store XML in the database. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (10/17/2016)


    My answer would be "None of the above" because I don't want people to store XML in the database. 😉

    Well ... there is also the case when programs are storing XML in the DB. It helps because there are lots of thinks with the syntax ( they need to be well formatted, ideally validated etc. )

    For example SSRS stores the reports as XML in the database.

  • Iulian -207023 (10/17/2016)


    Jeff Moden (10/17/2016)


    My answer would be "None of the above" because I don't want people to store XML in the database. 😉

    Well ... there is also the case when programs are storing XML in the DB. It helps because there are lots of thinks with the syntax ( they need to be well formatted, ideally validated etc. )

    For example SSRS stores the reports as XML in the database.

    Heh... well... that's a part of the reason why I think SSRS and similar programs are terrible and why you frequently get long duration spinners instead of an instant report. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (10/17/2016)


    Iulian -207023 (10/17/2016)


    Jeff Moden (10/17/2016)


    My answer would be "None of the above" because I don't want people to store XML in the database. 😉

    Well ... there is also the case when programs are storing XML in the DB. It helps because there are lots of thinks with the syntax ( they need to be well formatted, ideally validated etc. )

    For example SSRS stores the reports as XML in the database.

    Heh... well... that's a part of the reason why I think SSRS and similar programs are terrible and why you frequently get long duration spinners instead of an instant report. 😉

    🙂 good point just that well ... they exist there, and will stay for a while.

    What would you use for reporting for example?

    It would be nice to move them, the reports, to a lighter storage & execution environment.

    + it needs also an development environment too. ( I think there is quite an ecosystem around the reporting. )

    It would be nice to have a lighter option.

  • Ugh. I hate XML.

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

Viewing 8 posts - 16 through 22 (of 22 total)

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