Re: SQL Exists query in SPL If
Posted in 1996
David,
You probably should be able to do some such test as 'IF [NOT] EXISTS ...
THEN', but as you've found out via your experimentation, it cannot be done.
Either of your solutions will work. I'd suggest that the COUNT(*) one is
easier to handle as you get 0 or 1 (or more than 1, perhaps) as the answer;
the key thing is that you always get an answer. If you use the EXISTS
version, you have to worry about how to detect that no value was returned,
which isn't as easy as it should be.
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>
>From: Dave Harding <HARDID02@bh.bbc.co.uk>
>Date: 29 Jul 1996 15:28:11 GMT
>X-Informix-List-Id: <news.26617>
>
>All Gurus,
> In SPL, if I want to test the existance of a particular record, I either
>select count(*) into x_count ... or>select rowid into x_exists ..... and then test the value of either x_count
>or x_exists. It seems to me that you should be able to say something like
>"if [not] exists select ...then ...etc etc. I have had a bit of a fiddle
>but nothing is ever easy is it?
>Has anyone nutted this one out already or discovered that it can't be
>done, I'd appreciate some feedback.