Re: Can you use "If..Then" logic in SQL?

From: <rtproffitt_at_my-dejanews.com>
Date: Fri, 30 Apr 1999 15:46:37 GMT
Message-ID: <7gcj8r$ueo$1_at_nnrp1.dejanews.com>


Thomas Kyte's <tkyte_at_us.oracle.com> message was useful for giving me this idea. Try something like this:

Select decode( (t2.price is null and t2.date is null), t1.price, t2.price) as price, decode( (t2.price is null and t2.date is null),t1.date, t2.date) as date from t1, t2 where t1.key = t2.key (etc....)

This assumes you don't care if table 1 info is null.... It also assumes you have a reason for joining two different tables on "key" that have separate prices and dates....what I mean, is that it assumes that your original approach of joining the two tables is sound...

Good Luck.
Bob Proffitt

In article <7ganjk$de6$1_at_news.doit.wisc.edu>,   "Mitch" <mabaza25_at_usaDELETE.net> wrote:
>
>
> -- I am programming a VB app that pulls data from an Oracle 8 database into
> Access for further manipulation. I am trying to figure out if there is a
> way using either Oracle or Jet SQL to use "If..Then" logic in my SQL query.
> For example,
>
> "Select Table1.*, Table2.* where Table1.Key = Table2.Key (this is where I'm
> not sure about the syntax) and If Table2.Price and Table2.Date are NULL then
> Table1.Price, Table1.Date Else Table2.Price and Table2.Date"
>
> I am sure I could just pull all records from the Oracle database into Access
> and then use DAO methods to create another recordset that meets the above
> criteria, but that's bound to be very slow. I'd like to use strictly SQL if
> possible. Any and all suggestions (Oracle, Access or VB) are appreciated.
>
> Thanks
>
> Mitch Abaza
> mabaza25_at_DELETEusa.net
>
> clear "delete" to mail
>
>

-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Fri Apr 30 1999 - 17:46:37 CEST

Original text of this message