Re: if statement - Mailing list pgsql-novice

From Ludwig Lim
Subject Re: if statement
Date
Msg-id 20021022005718.27079.qmail@web80314.mail.yahoo.com
Whole thread Raw
In response to if statement  ("Devinder K Rajput" <Devinder.Rajput@ipaper.com>)
List pgsql-novice
--- Devinder K Rajput <Devinder.Rajput@ipaper.com>
wrote:
> 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.

  Use the CASE clause, it simulates the if-then-else
statement in SQL.

Try the following:
  SELECT a.number,
         a.description_1,
         a.description_2,
         ....
         ....
         CASE
           WHEN a.description_1 <> b.description_1
THEN
              'description_1'
           WHEN a.description_2 <> b.description_2
THEN
              'description_2'
           /* Some more WHEN-THEN statements.... */
         END
   FROM .....
   WHERE .....


regards,
ludwig.


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

pgsql-novice by date:

Previous
From: "working4aliving"
Date:
Subject: Re: Big Picture
Next
From: Joel Rodrigues
Date:
Subject: Re: Big Picture