Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

TOP in IF EXISTS

2 posts in General Discussion Last posting was on 2012-12-26 16:05:02.0Z
Karthik M Posted on 2012-12-26 06:26:27.0Z
Sender: 7da.50da88e5.1804289383@sybase.com
From: Karthik M
Newsgroups: sybase.public.ase.general
Subject: TOP in IF EXISTS
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <50da9892.d29.1681692777@sybase.com>
NNTP-Posting-Host: 172.20.134.41
X-Original-NNTP-Posting-Host: 172.20.134.41
Date: 25 Dec 2012 22:26:27 -0800
X-Trace: forums-1-dub 1356503187 172.20.134.41 (25 Dec 2012 22:26:27 -0800)
X-Original-Trace: 25 Dec 2012 22:26:27 -0800, 172.20.134.41
Lines: 18
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:31604
Article PK: 1158608

Hi All,

If i execute the below query , I am getting

"Incorrect syntax near the keyword 'TOP'."

is there any limitation to use TOP keyword in IF EXISTS ?

IF EXISTS (SELECT TOP 1 * FROM fox_auto_hedge_feed_in)
BEGIN
Print '1'
END

IF EXISTS (SELECT TOP 1 external_id FROM
fox_auto_hedge_feed_in)
BEGIN
Print '1'
END


Bret Halford Posted on 2012-12-26 16:05:02.0Z
From: Bret Halford <bret.halford@sap.com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 Thunderbird/16.0.2
MIME-Version: 1.0
Newsgroups: sybase.public.ase.general
Subject: Re: TOP in IF EXISTS
References: <50da9892.d29.1681692777@sybase.com>
In-Reply-To: <50da9892.d29.1681692777@sybase.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <50db202e$1@forums-1-dub>
Date: 26 Dec 2012 08:05:02 -0800
X-Trace: forums-1-dub 1356537902 172.20.134.152 (26 Dec 2012 08:05:02 -0800)
X-Original-Trace: 26 Dec 2012 08:05:02 -0800, vip152.sybase.com
Lines: 47
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:31612
Article PK: 1158619


On 12/25/2012 11:26 PM, Karthik M wrote:
> Hi All,
>
> If i execute the below query , I am getting
>
> "Incorrect syntax near the keyword 'TOP'."
>
> is there any limitation to use TOP keyword in IF EXISTS ?
>
> IF EXISTS (SELECT TOP 1 * FROM fox_auto_hedge_feed_in)
> BEGIN
> Print '1'
> END
>
> IF EXISTS (SELECT TOP 1 external_id FROM
> fox_auto_hedge_feed_in)
> BEGIN
> Print '1'
> END
>

Yes. TOP generally isn't allowed in subqueries*.
It also isn't necessary, the processing of IF EXISTS stops
once the scan finds the first matching row.

*derived tables / inline views might be thought of as
subqueries, TOP is allowed there:

1> select
2> id
3> from
4> (select top 3 id from sysobjects) dt1
5> go
id
-----------
1
2
3

(3 rows affected)


--
Bret Halford
Support Architect, ASE Tactical Support Team, AGS Primary Support
Sybase, Inc., an SAP Company
385 Interlocken Crescent, Suite 300, Broomfield, Colorado, 80021