The Attribute

  • TomThomson

    SSC Guru

    Points: 104772

    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

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 716336

    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.

  • TomThomson

    SSC Guru

    Points: 104772

    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

  • Jeff Moden

    SSC Guru

    Points: 994951

    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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

  • Iulian -207023

    SSCertifiable

    Points: 7508

    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.

  • Jeff Moden

    SSC Guru

    Points: 994951

    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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

  • Iulian -207023

    SSCertifiable

    Points: 7508

    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.

  • Koen Verbeeck

    SSC Guru

    Points: 258955

    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 23 (of 23 total)

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