🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #982

Re: IF condition

#982
From: Craig Stuntz TeamB
Date: Wed, 04 Apr 2007 14:53
21 lines
1640 bytes
aleplgr wrote:

> IF (SELECT COUNT(*) FROM TEMP WHERE (FLAG = 1) > 0) THEN
> BEGIN
> ...
> END

	*Don't* do this. It's *hugely* inefficient. Instead, do:

IF (EXISTS (SELECT 1 FROM TEMP WHERE (FLAG = 1)) THEN BEGIN

	Your version counts all records visible to your transaction, then
throws the result away.

	My version stops as soon as it finds one.

-- 
Craig Stuntz [TeamB] � Vertex Systems Corp. � Columbus, OH
  Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Borland newsgroup denizen Sergio Gonz�lez has a new CD of 
  Irish music out, and it's good: http://tinyurl.com/7hgfr
Technical Details
Message-ID: <4613adcd@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4613772b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,ba6f6a971f66229
X-Google-Attributes: gid114a0e,public
X-Google-Language: ENGLISH,ASCII
From: "Craig Stuntz [TeamB]" <craig_stuntz@nospam.please [a.k.a. acm.org]>
Subject: Re: IF condition
Newsgroups: borland.public.interbase.sql
References: <4613772b$1@newsgroups.borland.com>
Organization: Vertex Systems Corporation
User-Agent: XanaNews/1.18.1.5
X-Face: "huzh55Xi]!ZNni78>a*5+).`SK?<^q2MlHk-C]Z2M9T@\J5ZCB$95Ey+s"XQuhGFA[eutZ:0^AV!Q;t>gE`1-=8d;HZ6~*o1dH<X9\b$!|(}+I'!Xq)@3Op}%0ArW&nf'Qh*EwR
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 24.106.104.205
Message-ID: <4613adcd@newsgroups.borland.com>
Date: 4 Apr 2007 06:53:17 -0800
X-Trace: newsgroups.borland.com 1175694797 24.106.104.205 (4 Apr 2007 06:53:17 -0800)
Lines: 21
X-Authenticated-User: cstuntz
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail