Skip site navigation (1) Skip section navigation (2)

Re: if statement

From: Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com>
To: Devinder K Rajput <Devinder(dot)Rajput(at)ipaper(dot)com>
Cc: PostgreSQL Mailing List <pgsql-novice(at)postgresql(dot)org>
Subject: Re: if statement
Date: 2002-10-22 00:57:18
Message-ID: 20021022005718.27079.qmail@web80314.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
--- Devinder K Rajput <Devinder(dot)Rajput(at)ipaper(dot)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

In response to

  • if statement at 2002-10-21 16:45:09 from Devinder K Rajput

pgsql-novice by date

Next:From: Joel RodriguesDate: 2002-10-22 07:08:50
Subject: Re: Big Picture
Previous:From: working4alivingDate: 2002-10-22 00:36:01
Subject: Re: Big Picture

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group