Need output as 1,2,3,...10

  • RBarryYoung (1/17/2009)


    This being an ORDER BY on the outermost SELECT, it seems that it is guaranteed to be so sorted.

    I don't think so it holds in all cases, especially when using case statement, 'cause I do fallen into this many times and only to find it at the last moment.

    I would be posting the samples when I am back to work...

    --Ramesh


  • ... and, still, in an interview, none of the solutions are the correct answer.

    Other than a firedrill on this forum, when have any of you actually had to concatenate data in SQL Server in such a fashion in production?

    --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 (1/18/2009)


    ... and, still, in an interview, none of the solutions are the correct answer.

    Heh, I guess that depends on who's asking. 😛

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Jeff Moden (1/18/2009)


    Other than a firedrill on this forum, when have any of you actually had to concatenate data in SQL Server in such a fashion in production?

    Couple times, but only very small numbers of rows, like using sys.columns to generate an insert script in code. I neither store nor retrieve data concatenated, so have no need to do this on large row sets

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I am not a very experienced guy, still I never faced this things in production.

    But the thing is, i have faced the same question twice in interview. May b the interviewer used it in their system 😀

  • Jeff Moden (1/18/2009)


    Other than a firedrill on this forum, when have any of you actually had to concatenate data in SQL Server in such a fashion in production?

    For the record, I have had to do it once, about 5 years ago. Not quite like this case (which seems silly and too simple), but the more typical "Group By and concatenate all Z column values in the group".

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • I guess that's what I'm getting at, folks. My answer to such a question in an interview would be to first answer the question correctly as many of you have done and then I would tell the interviewer, "But this is a form of denormalization that, with very rare exception, should ever be done in a database unless it's for the creation of some form of dynamic SQL."

    --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 (1/19/2009)


    I guess that's what I'm getting at, folks. My answer to such a question in an interview would be to first answer the question correctly as many of you have done and then I would tell the interviewer, "But this is a form of denormalization that, with very rare exception, should ever be done in a database unless it's for the creation of some form of dynamic SQL."

    Heh. Wow, you're right of course, I do use this technique for Dynamic SQL generation all the time. I can't believe that I forgot that, complete brain freeze. :w00t:

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

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

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