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!

Help please...trouble with a CASE statement for SQL

Status
Not open for further replies.

sa113

IS-IT--Management
Nov 20, 2003
7
0
0
US
For some reason this derived field is not coming up ok when testing it. What am I missing? I'm trying to get a ranged grouping going here.

CASE (FLOOR(DATEDIFF (DD, PS_EMPLOYMENT.CMPNY_SENIORITY_DT, "PS_EMPLOYMENT"."TERMINATION_DT")) / 365.25)
WHEN < 1 THEN 'Less then 1 year'
WHEN > 1 < 2 THEN '1 to 2 years'
WHEN > 2 THEN 'More then 2 years'
END
 
Your formula isn't written correctly. I think the placement of the derived formula you're using in this formula is wrong, and you haven't included an ELSE option.

Try this:
CASE
WHEN (insert your "floor" derived formula here) <1 THEN 'less than 1 year'
WHEN (insert your "floor" derived formula here) >2
THEN 'more than 2 years'
ELSE '1 to 2 years'
END
 
Thanks for the reply. I finally did this following formula and it worked:

CASE
WHEN (FLOOR(DATEDIFF (DD, PS_EMPLOYMENT.CMPNY_SENIORITY_DT, "PS_EMPLOYMENT"."TERMINATION_DT")) / 365.25) < 1.00 THEN '< 1 year'
WHEN (FLOOR(DATEDIFF (DD, PS_EMPLOYMENT.CMPNY_SENIORITY_DT, "PS_EMPLOYMENT"."TERMINATION_DT")) / 365.25) BETWEEN 1 AND 2 THEN '> 1 < 2 years'
WHEN (FLOOR(DATEDIFF (DD, PS_EMPLOYMENT.CMPNY_SENIORITY_DT, "PS_EMPLOYMENT"."TERMINATION_DT")) / 365.25) > 2 THEN '> 2 years'
END


Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top