From: | Alex <alex(at)meerkatsoft(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | HELP with a Query |
Date: | 2004-02-21 08:20:51 |
Message-ID: | 403714E3.2060600@meerkatsoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I need some help with a query.
I use a reference table to lookup some codes. Everything works well if the reference table contains a reference but the query fails if no reference fails (Z.ref_code=123456).
What I need to is either return 0 or null into Z.prim_exch if no reference can be found. Whats the best way to do that ? I tried a sub query but also did not succeed.
SELECT A.sec_code,A.exch_code,A.price_date,Z.prim_exch,
CASE
WHEN A.exch_code = Z.prim_exch THEN 1
ELSE 0
END AS is_prim
FROM price_hist AS A, references AS Z
WHERE A.price_date <= '20040219' AND A.sec_code=123456 AND Z.ref_code=123456 LIMIT 10;
Thanks for any help.
Alex
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2004-02-21 08:55:59 | Re: HELP with a Query |
Previous Message | V i s h a l Kashyap @ [Sai Hertz And Control Systems] | 2004-02-21 06:56:47 | Re: embeding postgre |