Page 1 of 1

Unified SQL for TOP n or LIMIT n

Posted: Wed 05 May 2010 04:33
by hughespa
Hi,

I was trying to come up with a good way of specifying TOP 1 or LIMIT 1 when using SQL Server or PostgreSQL DB's.

For now I have defined macros {TOP_1} and {LIMIT_1} and a typical query look like this:

SELECT {TOP_1} ID FROM SOME_TABLE {LIMIT_1}

Where {TOP_1} is defined for SQL Server and {LIMIT_1} is defined for PostgreSQL.

This isn't very clever for TOP 5 or LIMIT 10 though...

Is there a clever way to do it?

Thanks in advance,

Regards, Paul.

Posted: Thu 06 May 2010 14:22
by bork
Hello

You should write your query like this:

Code: Select all

SELECT {TOP_MACROS 5} ID FROM SOME_TABLE {LIMIT_MACROS 5} 
In this case the "TOP_MACROS" and "LIMIT_MACROS" will be replaced by your value and string after space ("5") will be added in the end. You can find more detailed information about this in the Unified SQL section of the UniDAC help.

Posted: Fri 07 May 2010 00:35
by hughespa
Thanks Bork,

That's great.

I didn't notice the line in help which explained being able to add additional text when you use a macro in the SQL.

Regards, Paul.