Sales puzzle

  • chgn01

    Hall of Fame

    Points: 3537

    Comments posted to this topic are about the item Sales puzzle

    --------------------------------------
    ;-)β€œEverything has beauty, but not everyone sees it.” ― Confucius

  • Lokesh Vij

    SSChampion

    Points: 10836

    Ah! Very simple question to start the day. Thanks Gary:-)

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • kapil_kk

    SSC-Insane

    Points: 21316

    Lokesh Vij (8/13/2013)


    Ah! Very simple question to start the day. Thanks Gary:-)

    +1 πŸ™‚

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

  • Danny Ocean

    SSCertifiable

    Points: 6098

    kapil_kk (8/13/2013)


    Lokesh Vij (8/13/2013)


    Ah! Very simple question to start the day. Thanks Gary:-)

    +1 πŸ™‚

    +1:-)

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

  • This was removed by the editor as SPAM

  • Hany Helmy

    SSChampion

    Points: 13321

    Thanx 4 the easy question πŸ™‚

  • kaspencer

    SSCarpal Tunnel

    Points: 4255

    I have worked with SQL Server on and off for many years, but I don't think I recall ever seeing "ORDER BY [number]" as it appears in this question.

    Could some kindly person explain this to me, because a clear explanation seems to be difficult to locate in the documentation, and in searches. This little issue was why I failed this question!

    Many thanks

    Kenneth Spencer

    You never know: reading my book: "All about your computer" might just tell you something you never knew!
    lulu.com/kaspencer

  • Hany Helmy

    SSChampion

    Points: 13321

    kaspencer (8/14/2013)


    I have worked with SQL Server on and off for many years, but I don't think I recall ever seeing "ORDER BY [number]" as it appears in this question.

    Could some kindly person explain this to me, because a clear explanation seems to be difficult to locate in the documentation, and in searches. This little issue was why I failed this question!

    Many thanks

    Kenneth Spencer

    Order by [some number], this number indicates the order of the column in the Select clause.

    Hope that would help you.

  • Hany Helmy

    SSChampion

    Points: 13321

    hany.helmy (8/14/2013)


    kaspencer (8/14/2013)


    I have worked with SQL Server on and off for many years, but I don't think I recall ever seeing "ORDER BY [number]" as it appears in this question.

    Could some kindly person explain this to me, because a clear explanation seems to be difficult to locate in the documentation, and in searches. This little issue was why I failed this question!

    Many thanks

    Kenneth Spencer

    Order by [some number], this number indicates the order of the column in the Select clause.

    Hope that would help you.

    Like for example:

    Select EmpId, EmpName, DeptId, DeptName

    From SomeTable

    Order by 2 -- this indicates that the result set will be sorted by column no. 2 in the Select clause which is 'EmpName'.

    Regards,

    Hany Helmy

  • Dineshbabu

    Hall of Fame

    Points: 3220

    kaspencer (8/14/2013)


    I have worked with SQL Server on and off for many years, but I don't think I recall ever seeing "ORDER BY [number]" as it appears in this question.

    Could some kindly person explain this to me, because a clear explanation seems to be difficult to locate in the documentation, and in searches. This little issue was why I failed this question!

    Many thanks

    Kenneth Spencer

    Hi kenneth,

    In Order By we can specify integer representing the position of the column in the select list. The result set will be sorted based on the column. For further details pls refer

    http://technet.microsoft.com/en-us/library/ms188385.aspx

    Also FYI, Order By has no effect in this question, without sorting also you will get the same result, Its matter of Where clause.

    I hope you are aware of Where clause will be applied before Order By.

    --
    Dineshbabu
    Desire to learn new things..

  • tom.w.brannon

    Hall of Fame

    Points: 3956

    I use numbers in my order by statements every day for short queries. It is faster than typing out long names and is especially nice when the column is some kind of calculatoni, function or case statement. I would not use them for production systems but for just checking around it my data they have been wonderful

  • kapil_kk

    SSC-Insane

    Points: 21316

    Dineshbabu (8/14/2013)


    kaspencer (8/14/2013)


    I have worked with SQL Server on and off for many years, but I don't think I recall ever seeing "ORDER BY [number]" as it appears in this question.

    Could some kindly person explain this to me, because a clear explanation seems to be difficult to locate in the documentation, and in searches. This little issue was why I failed this question!

    Many thanks

    Kenneth Spencer

    Hi kenneth,

    In Order By we can specify integer representing the position of the column in the select list. The result set will be sorted based on the column. For further details pls refer

    http://technet.microsoft.com/en-us/library/ms188385.aspx

    Also FYI, Order By has no effect in this question, without sorting also you will get the same result, Its matter of Where clause.

    I hope you are aware of Where clause will be applied before Order By.

    Nice explanation Dinesh πŸ™‚

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

  • Ed Wagner

    SSC Guru

    Points: 286958

    You know, a simpler question is nice every once in a while. In fact, I found myself studying it to see what I missed. πŸ™‚ Thanks.

  • aochss

    SSCommitted

    Points: 1677

    tom.w.brannon (8/14/2013)


    I use numbers in my order by statements every day for short queries. It is faster than typing out long names and is especially nice when the column is some kind of calculatoni, function or case statement. I would not use them for production systems but for just checking around it my data they have been wonderful

    Agree with Tom. We did have this "feature" used in production and it caused issues when an additional column was added to the select causing the "ORDER BY" to bring the records back in an order that was not expected.

    However, as Tom mentioned, this is great when doing sub queries, unions or aggregates to do a quick check on the date without having to define aliases or use the calculation in the order by clause.

    Anton

  • Dana Medley

    SSCertifiable

    Points: 6764

    Good question. It's a shame that in my dazed state I knew the right answer, but picked the wrong one. Time to go have some magic caffeinated elixir.



    Everything is awesome!

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

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