🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to use a an integer parameter to fetch parameter = "N" or all rows.

#850
From: Mitch
Date: Wed, 30 May 2007 16:33
35 lines
2086 bytes
Wayne Niddery [TeamB] wrote:
> Mitch wrote:
>> How can I easily query an integer column to get all the rows matching
>> an integer or also allow all rows to be fetched? EG:
>>
>> Item.Project (integer)
>> Item.Location (integer)
>>
>> (Case 1)
>> Select * from Item where
>> Project = :ProjectID and Location = :LocationID
>>
>> (Case 2)
>> Select * from Item where
>> Project = :ProjectID and Location = all locations
> 
> If you really cannot change the SQL to drop the location condition, then the 
> only way is to test the parameter in the SQL as well, but doing this will 
> mess up use of indexes and thus may result in poor performance - you'll have 
> to test this:
> 
> Select * from Item where
> (Project = :ProjectID or :ProjectID is null)
> and
> (Location = :LocationID or :LocationID is null)
> 
>

Thanks Wayne. This seems to be working:
WHERE
  ProjectID = :ProjectID and (LocationID = :LocationID or :all_locations 
=1 )

If I set :all_locations = 0 then only locationID shows.
If I set :all_locations = 1 then all locationIDs show.
Technical Details
Message-ID: <465da751$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <465d29fa$1@newsgroups.borland.com> <465d8a1c$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,d43d3e3c175ab47e
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 30 May 2007 17:33:18 +0100
From: Mitch <mmm@yyy.com>
User-Agent: Thunderbird 2.0.0.0 (Windows/20070326)
MIME-Version: 1.0
Newsgroups: borland.public.interbase.sql
Subject: Re: How to use a an integer parameter to fetch parameter = "N" or
 all rows.
References: <465d29fa$1@newsgroups.borland.com> <465d8a1c$1@newsgroups.borland.com>
In-Reply-To: <465d8a1c$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 82.152.165.26
Message-ID: <465da751$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1180542801 82.152.165.26 (30 May 2007 09:33:21 -0700)
Lines: 35
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail