variablessybasesybase-ase15

Create Dynamic Query in Sybase SELECT TOP X


I am wondering how to do the following in Sybase 15.

DECLARE @DEPTH INT
SET @DEPTH = 8    
SELECT TOP @DEPTH  * FROM Table

It gives me the following error : Error (102) Incorrect syntax near '@DEPTH'.

I tried using TOP (@DEPTH), same way as sql server but it recognizes it as an error.

Error (14216) Function 'TOP' not found. If this is a SQLJ function or SQL function, use sp_help to check whether the object exists (sp_help may produce a large amount of output).

Thank you


Solution

  • The answer is:

    DECLARE @DEPTH INT
    SET @DEPTH = 8    
    SET ROWCOUNT @DEPTH
    SELECT * FROM Table
    SET ROWCOUNT 0