Question

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?

Was it helpful?

Solution

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;
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top