Re: if statement
| От | Ludwig Lim |
|---|---|
| Тема | Re: if statement |
| Дата | |
| Msg-id | 20021022005718.27079.qmail@web80314.mail.yahoo.com обсуждение |
| Ответ на | if statement ("Devinder K Rajput" <Devinder.Rajput@ipaper.com>) |
| Список | 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 по дате отправления: