From: | "Devinder K Rajput" <Devinder(dot)Rajput(at)ipaper(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | if statement |
Date: | 2002-10-21 16:45:09 |
Message-ID: | OF39804F6D.3E809375-ON86256C59.005A3C80@ipaper.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi,
I am trying to find out how to do an if statement/case statement inside a
select. I am comparing item records to find out what is different. Rather
than writing a query for comparing each field separately, I just want to
tell which field is different by printing the name of that field. Thank
you.
select
a.number,
a.description_1,
a.description_2,
b.description_1,
b.description_2,
a.hub_id,
b.hub_id,
a.category,
b.category,
a.sub_category,
b.sub_category,
--what I would like to say--
if a.description_1 <> b.description_1 "description_1"
else if a.description_2 <> b.description_2 "description_2"
else if ...
---back to rest of query---
from items as a, items as b
where a.number = b.number
and a.hub_id <> b.hub_id
and (a.category <> b.category OR a.sub_category <> b.sub_category OR
a.prime_vendor <> b.prime_vendor OR a.description_1 <>
b.description_1 OR
a.description_2 <> b.description_2 OR a.prc_unit <> b.prc_unit
OR
a.alt_unit_1 <> b.alt_unit_1 OR a.alt_unit_2 <> b.alt_unit_2
OR
a.alt_unit_3 <> b.alt_unit_3 OR a.prime_vendor_cost <>
b.prime_vendor_cost )
and a.hub_id < b.hub_id
Devinder Rajput
Stores Division Corporate Offices
Chicago, IL
(773) 442-6474
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew McMillan | 2002-10-21 18:48:29 | Re: db design question |
Previous Message | Josh Berkus | 2002-10-21 15:54:45 | Re: how to create secondary key!! |