Problem with 'Select top N statement'

  • Can anybody help on this?

    I am executing a sql statement in the following form:

    use tradeshow

    select top 1 *

    from housingoccupants

    .. and i always get the follwing message

    Server: Msg 170, Level 15, State 1, Line 2

    Line 2: Incorrect syntax near '1'.

    the table has valid rows in it. In fact, if i select another database from the sql analyzer, then execute the sql statement, it gives me the results. But it does not execute the query with the database selected on the analyzer's select tab.

    It's puzzling! and i need somebody who encountered this error before.

    thanks ...

  • Check the database compatibility in the database properties It's probably set for 65 (SQL Server 6.5). TOP wasn't a valid keyword in SQL Server 6.5.

    K. Brian Kelley

    http://www.truthsolutions.com/

    Author: Start to Finish Guide to SQL Server Performance Monitoring

    http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1

    K. Brian Kelley
    @kbriankelley

  • thanks for the response brian ...

    i'm using sql 7 sp4. where exactly in the properties does this parameter set?

    thanks

  • Don't know about SQL 7 but in 2000, right click on db, choose Options tag, (or go to Tools and select Options), Compatability Level is at the bottom (6.5 would be 65).



    Everett Wilson
    ewilson10@yahoo.com

  • thanks everybody!

    in sql7, the setting is done thru sp_dbccmptlevel. it should be set to 70.

    the error on the select top n statement did NOT is gone.

    again ... thanks

Viewing 5 posts - 1 through 4 (of 4 total)

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