Subject Re: [firebird-support] Check if record exist
Author Thomas Steinmaurer
> I want to check if a record exist in SQL. Of course I could use:
> Select Count(*) From Person Where PersId=:PersId
> and check if a what is returned is higher than 0, but if there are a lot of records that will take a lot of time
>
> I want to something like:
> Select First 1 Count(*) From Person Where PersId=:PersId
>
> Or
> Select Count(*) From Person Where PersId=:PersId And RecordCount<2
>

If you need the check in PSQL (stored procedure or trigger), then try:

...
IF (EXISTS(SELECT 1 FROM PERSON WHERE PERSID = :PERSID)) THEN
BEGIN
...
END
...



--
HTH,
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database and MS SQL Server
Upscene Productions
http://www.upscene.com