tags:

views:

26

answers:

1

Hi there,

I need to alter a macro the way that a parameter can be passed to control the max size of the result set.

My idea was this SQL:

REPLACE MACRO myMacro
( maxRows INTEGER DEFAULT 100 )
AS
(
    SELECT TOP :maxRows
    FROM myTable;
);

But all I get is the message:

[SQLState 42000] Syntax error,Expected something like an Integer or decimal number between 'top' and ':'.

It's not possible for me to do this in any other way than a macro.

How can I do that?

+3  A: 

I found a way to do this:

REPLACE MACRO myMacro
( maxRows INTEGER DEFAULT 100 )
AS
(
    SELECT 
        ROW_NUMBER() OVER (ORDER BY myColumn) AS RowNo, 
        myColumn
    FROM myTable
    WHERE RowNo <= :maxRows;
);
Lars
Another option is dynamic SQL in a stored procedure using the DBC.SysExecSQL() function. However, the use of ROW_NUMBER() in this case does affect the results returned. In your original query you did not specify an ordered set.
RobPaller
I believe `<` should be `<=`.
lins314159