Need help converting Access SQL to Oracle [message #429548] |
Wed, 04 November 2009 08:38  |
synapse5150 Messages: 2 Registered: November 2009 Location: St. Louis, MO |
Junior Member |
|
|
I'm having a problem converting a query from Access SQL to Oracle. My problem is with the Access Iif statement. I thought it would be as simple as using the 'DECODE' function, but am having problems. Here's the portion of the Access SQL I am having trouble converting:
SELECT PERSONID,
Sum(IIf([INVOICEDATE]>=#1/1/2002#,IIf([INVOICEDATE]<#2/1/2002#,[SHIPPING],0),0)) AS Jan02U,
Sum(IIf([INVOICEDATE]>=#2/1/2002#,IIf([INVOICEDATE]<#3/1/2002#,[SHIPPING],0),0)) AS Feb02U,....Continues on until 4/1/2009
From NETSALESEXTRACT
Group by PERSONID
Basicaly what I am trying to do is return the [SHIPPING] field if the invoice date is between Jan 1st and Feb 1st. If not, the query returns 0 for that field.
Any help on how to re-write this for Oracle would be greatly appreciated.
Thank you all in advance!1
|
|
|
|
|
| Re: Need help converting Access SQL to Oracle [message #429555 is a reply to message #429553] |
Wed, 04 November 2009 09:00   |
JRowbottom Messages: 5371 Registered: June 2006 Location: Sunny North Yorkshire, ho... |
Senior Member |
|
|
So you'd need something like:SELECT Personid
,sum(case when invoice_date between to_date('01-jan-2002','dd-mon-yyyy') and to_date('01-feb-2002','dd-mon-yyyy') then SHIPPING else 0 end)
FROM <table>
GROUP BY personid;
|
|
|
|