Subject Re: [firebird-support] What is the BEST method to find if a record exists?
Author Fernando Buitrago
I use

If (Exists(Select * from Table Where .....)) then
PARAM_EXISTE = 'T';
else
PARAM_EXISTE = 'F';

Where PARAM_EXISTE is Char(1).

Is very important to write the params in WHERE correctry.

This method is so easy, donĀ“t you think?

REgards.

Fer

On Tue, 16 Nov 2004 17:06:36 -0500, Michael L. Horne <guardian@...> wrote:
>
> Hello,
>
> I need to check to see if a record exists from inside a
> stored procedure. What is the best code to use?
>
> The methods I know of are:
>
> 1.
> NO_RECORD_EXISTS = 'FALSE';
> select count(*) from testfile where testfield='xxxxx' into :numrecords;
> if (numrecords = 0) then NO_RECORD_EXISTS = 'TRUE';
>
> 2.
> NO_RECORD_EXISTS = 'FALSE';
> for select testfield from testfile where testfield='xxxxx' into :testfield
> do begin
> NO_RECORD_EXISTS = 'TRUE';
> end
>
> 3. /* this one doesn't seem to work correctly and I am not sure why */
> NO_RECORD_EXISTS = 'FALSE';
> select first 1 testfield from testfile where testfield='xxxxx' into
> :testfield;
> if (testfield = null) then NO_RECORD_EXISTS = 'TRUE';
>
> -------
> But these all seem like a difficult set of things to do to find out if a
> record exists, so is there a better way and what is it?
>
> Thanks
> Michael L. Horne
>
>
>
> Yahoo! Groups Links
>
>
>
>
>