Re: How to include an IF() statement in SQL?

From: <prochak_at_my-dejanews.com>
Date: 1998/09/02
Message-ID: <6sjll4$li9$1_at_nnrp1.dejanews.com>#1/1


Actually to map it closer to what his sample pseudostatement looks like, I assume he meant to concatenate the columns where he used commas, it could be written:

select customers.parentid || '' || customers.name as parent_name from customers
where customers.custid=customers.parentid || '' || customers.name ;

The WHERE clause is normally the conditional (IF) in SQL. DECODE is a little overkill in this case.

In article <6sjd03$6oj$2_at_relay1.dsccc.com>,   jstrange_at_imtn.dsccc.com (John Strange) wrote:
>
> select name
> from customers
> where custid exists (select parentid
> from customers)
>
> Bob Cunningham (bcunn_at_oanet.com) wrote:
> : On Tue, 01 Sep 1998 17:30:40 -0700, Troy Perchotte <max_at_headroom.com>
> : wrote:
 

> : >How do I include a condition within a select statement?
> : >Something like the following (only one that works):
> : >
> : >select if(customers.custid=customers.parentid,'',customers.name) as
> : >parent_name from customers;
> : >
> : >Troy Perchotte
> : >
> : >
 

> : You can use the DECODE function. E.g.:
 

> : SELECT DECODE(custid,parentid,NULL,name) parent_name FROM customers;
 

> : Bob Cunningham
> : bcunn_at_oanet.com
>

--
Ed Prochak
Magic Interface, Ltd.
440-498-3702

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Received on Wed Sep 02 1998 - 00:00:00 CEST

Original text of this message