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!

IF ElseIF 1

Status
Not open for further replies.

Olivia123

MIS
Apr 19, 2007
29
0
0
US
Hello,
Im having trouble placing IF and ELSEIF in the right place.
Basically I need IF "A" = 1000 then do this... ELSE IF "A"= 2000 then do this.....
I have to add "IF" before CASE and the ELSEIF to continue with statement.

This is what i have now....

SELECT
*
FROM ( a, b, c, d,
CASE
WHEN .....THEN .....
WHEN......THEN......

END AS xxxxx
from f_all_hist)
WHEN a = '1000' i also have a = 2000 with different WHEN......THEN......
How can i use IF and ELSEIF *inside* the sql statment. I should have only one SELECT stament, not sure if one CASE:

Something like this (This is wrong!)
SELECT
*
FROM (
SELECT a, b, c, d, e,
IF a = '1000' THEN
(CASE
WHEN b BETWEEN 4001 AND 4500
THEN 'D
ELSIF a = '2000'
THEN ( CASE
WHEN b BETWEEN 4001 AND 4500
THEN N
end as ……………..
from ……………)


Thank you
 
it appears as though you have already have some familiarity with the CASE expression

just use CASE where you want to use IF

nested CASE expressions are allowed

however, you can also use ANDs and ORs in the WHEN clauses, so nesting is often not necessary

:)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top