Results 1 to 17 of 17

Thread: SQL top

Hybrid View

  1. #1
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL top

    What's the description of the error raised?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL top

    You could paste it into Access and execute it. It should give a descriptive error message.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL top

    you can try with the attached project
    Attached Files Attached Files

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL top

    You just missed some & and "...

    VB Code:
    1. sql1 = "Select Top 3 * From ( " & _
    2.      "select pontosind1 as Totais, classifind1 as Classifind, seccao1 as Secção, classe1 as Classe, designacao1 as Designação, nomesocio as Expositor, anilha1 as Anilha, gaiolaind1 as Gaiola, Sexo1 as Sexo" & _
    3.      " from exposicao " & _
    4.      " WHERE pontosind1 >= '90'" & _
    5.      " and (pontoseq1 = '' or pontoseq1 is null) " & _
    6.      " UNION ALL" & _
    7.      " select pontosind2, classifind2, seccao2, classe2, designacao2, nomesocio, anilha2, gaiolaind2, sexo2" & _
    8.      " from exposicao " & _
    9.      " WHERE pontosind2 >= '90'" & _
    10.      " and (pontoseq1 = '' or pontoseq1 is null) " & _
    11.      " UNION ALL" & _
    12.      " select pontosind3, classifind3, seccao3, classe3, designacao3, nomesocio, anilha3, gaiolaind3, sexo3" & _
    13.      " from exposicao " & _
    14.      " WHERE pontosind3 >= '90'" & _
    15.      " and (pontoseq1 = '' or pontoseq1 is null) " & _
    16.      " UNION ALL" & _
    17.      " select pontosind4, classifind4, seccao4, classe4, designacao4, nomesocio, anilha4, gaiolaind4, sexo4" & _
    18.      " from exposicao " & _
    19.      " WHERE pontosind4 >= '90'" & _
    20.      " and (pontoseq1 = '' or pontoseq1 is null)) " & _
    21.      " ORDER BY classe desc,Totais desc "
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL top

    yes you are right...now the code work,but the "top 3" don't extract the desired values because the top 3 extract only 3 recordsets and not all the 3 big recordsets....strange!!!!!!!


    Can you see the project attached,and run it,and change the top 3 for top 10?


    Thanks
    Attached Files Attached Files

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL top

    You are missing an ORDER BY outside the subquery...

    SELECT TOP 3 * FROM (...) ORDER BY TOTAIS DESC

    Without that you are not going to get the proper top 3 - numerically highest.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL top

    sory but I don't understand...I have a order outside of the subquery...I Think!!!!

    do you have see the project?

    Thnaks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width