Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Access SQL into Oracle equivalent

Status
Not open for further replies.
Dec 13, 2002
109
GB
I have Access code that sums the number of occurances of an integer calculation [Days taken]

Oracle doesn't like IIf

SELECT Sum(IIf([Days taken] Between 1 And 3,1,0)) AS [1-3]

 
Ronald,

There are multiple methods to achieve your result in Oracle. Here are four of those methods:
Code:
select sum(1) from <table_name> where days_taken between 1 and 3;
Code:
select count(*) from <table_name> where days_taken between 1 and 3;
Code:
select sum(case when days_taken between 1 and 3 then 1) from <table_name>;
Code:
select sum(decode(days_taken,1,1,2,1,3,1)) from <table_name>;
Let us know which method you prefer.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Sorry, Ronald...I forgot the "as [1-3]" part of your question.

In each of my "select" statements above, you can define the column alias with the addition of the following code snippet:
Code:
select ... as "[1-3]" from...

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
...and the word as is optional in this context in Oracle. I.e., this works, too:
Code:
select ... "[1-3]" from...

Okay, now I think I'm done. <grin>

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Oops...one more correction/addition -- I forgot the "end" to terminate the "case" statement, above. It should read:
Code:
select sum(case when days_taken between 1 and 3 then 1 [B][I]end[/I][/B]) from <table_name>;

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top