SELECT options

  • Hugo Kornelis (4/13/2012)The syntax used in this question is deprecated

    Is it definitely deprecated? The help page doesn't say so, just that the parentheses are optional for backward compatibility and recommends their use. But this wouldn't be the first time that the online help was missing something 🙂

  • Toreador (4/13/2012)


    Hugo Kornelis (4/13/2012)The syntax used in this question is deprecated

    Is it definitely deprecated? The help page doesn't say so, just that the parentheses are optional for backward compatibility and recommends their use. But this wouldn't be the first time that the online help was missing something 🙂

    I think you may be right. I guess I read too much into that BOL quote when I first saw it, and then remembered my cocnclusion instead of the actual text. I can't find any deprecation note anywhere.


    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/

  • This was removed by the editor as SPAM

  • Good question and leraned something today. I have never used WITH TIES before. I got it wrong but that was because I was trying to work it out in my head without ordering the data. Roll on lunch time!!!

  • very good question!!

    I've never used WITH TIES !!!!

    I learned anything today!!

    thanks!!!!


    [font="Times New Roman"]rfr.ferrari[/font]
    DBA - SQL Server 2008
    MCITP | MCTS

    remember is live or suffer twice!
    the period you fastest growing is the most difficult period of your life!
  • Fairly easy question, I think. Hardest part was to sort the data :p

  • Thanks for the question

    Iulian

  • Nice Question

    I never use the Ties Option

  • masteratul25 (4/12/2012)


    I am getting the below. Please correct me.:cool:

    I am also getting an error when opening your attachment. Can you please re-post and attach screenshot as JPG?

    Thanks,

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • Hugo Kornelis (4/13/2012)


    1. It would have been better to present the data ordered by salary. I first tried to order them by head, but I was constantly afraid that I'd overlook something. I ended up creating a table, putting in the salary values from the question, and running a SELECT * FROM ThatTable ORDER BY value DESC, just so that I could see the values in order to work out the correct example.

    I just pasted it into Excel and used text to columns, but the same principal applies. Looking at 10 rows not ordered by the amount that the top N clause followed, I realized that first I had to order them so I could figure out where top 80% or top 5 went.

    Nice question elsewise though, I use top occasionaly, but have never used WITH TIES.... at first I thought it was a 2012 feature and I planned to complain about not specifying 2012, but looked it up to be sure, and was shocked that I hadn't noticed it before. 🙂

    good question.



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • Hugo Kornelis (4/13/2012)


    Good question about some little known features (PERCENT and WITH TIES) of the TOP clause.

    1. It would have been better to present the data ordered by salary. I first tried to order them by head, but I was constantly afraid that I'd overlook something. I ended up creating a table, putting in the salary values from the question, and running a SELECT * FROM ThatTable ORDER BY value DESC, just so that I could see the values in order to work out the correct example.

    I entered the values in random order so it would not be that easy or obvious when you look at it on the screen 🙂 . That way you would have to at least manually sort them using paper and pencil.

    2. The syntax used in this question is deprecated; Microsoft recommends always using parentheses with the TOP clause: TOP (5), TOP (5) WITH TIES, TOP (80) PERCENT, and TOP (80) PERCENT WITH TIES.

    I realized about that after submitting the question, but couldn't find a chance to correct it. Though not fully deprecated yet Microsoft recommends the parentheses are used in the TOP clause.

    Thank you for your comments.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • Hugo Kornelis (4/13/2012)


    Toreador (4/13/2012)


    Hugo Kornelis (4/13/2012)The syntax used in this question is deprecated

    Is it definitely deprecated? The help page doesn't say so, just that the parentheses are optional for backward compatibility and recommends their use. But this wouldn't be the first time that the online help was missing something 🙂

    I think you may be right. I guess I read too much into that BOL quote when I first saw it, and then remembered my cocnclusion instead of the actual text. I can't find any deprecation note anywhere.

    I too thought this was a bit strange but thought Hmm, I guess I will have to change the way I write TOP queries. Then I thought when right clicking on a table and choosing "Select Top 1000 Rows" there are no () surrounding the number. Thanks for following up and clarifying.

  • EL Jerry (4/13/2012)


    I entered the values in random order so it would not be that easy or obvious when you look at it on the screen 🙂 . That way you would have to at least manually sort them using paper and pencil.

    Yeah, but that's exactly the part I have trouble with. Was the intention of the QotD to test my understanding of TOP, WITH TIES, and PERCENT, of was it to test my ability to sort numbers?

    But please don't let this minor comment put you off from submitting more questions! As I already said in my first comment, I do like the question!


    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/

  • Daniel Bowlin (4/13/2012)Then I thought when right clicking on a table and choosing "Select Top 1000 Rows" there are no () surrounding the number.

    So there aren't. How very Microsoft!

  • mtassin (4/13/2012)


    I just pasted it into Excel and used text to columns, but the same principal applies. Looking at 10 rows not ordered by the amount that the top N clause followed, I realized that first I had to order them so I could figure out where top 80% or top 5 went.

    Actually, TOP... WITH TIES requires that ORDER BY is specified.

    Nice question elsewise though, I use top occasionaly, but have never used WITH TIES.... at first I thought it was a 2012 feature and I planned to complain about not specifying 2012, but looked it up to be sure, and was shocked that I hadn't noticed it before. 🙂

    good question.

    I had learned this since the SQL Server 2000 days, but I guess this is a rarely used feature.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

Viewing 15 posts - 16 through 30 (of 60 total)

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