• B.A. Cooper (7/7/2008)


    The following code works, but either of the commented lines produce a syntax error in my environment. When the code from the article is cut and pasted it produces the same error. Is there a configuration setting that allows this to work?

    DECLARE @N INT

    SET @N = 5

    select TOP 5 * from table_name

    --select TOP @N * FROM table_name

    --select TOP (@N) * FROM table_name

    For SQL Server 2000, a programmable TOP is NOT available unless you do the dynamic SQL thing... you can, however, use rowcount...

    DECLARE @N INT

    SET @N = 5

    SET ROWCOUNT @N

    SELECT * FROM table_name

    SET ROWCOUNT 0

    --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)