Unified SQL for TOP n or LIMIT n

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
hughespa
Posts: 81
Joined: Sat 23 Aug 2008 08:36
Location: W. Australia

Unified SQL for TOP n or LIMIT n

Post by hughespa » Wed 05 May 2010 04:33

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.

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Post by bork » Thu 06 May 2010 14:22

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.

hughespa
Posts: 81
Joined: Sat 23 Aug 2008 08:36
Location: W. Australia

Post by hughespa » Fri 07 May 2010 00:35

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.

Post Reply