We help IT Professionals succeed at work.
Get Started

Sql Case Expression (Nested)

127 Views
Last Modified: 2015-08-19
I am trying to create a worksheet in my Business Intelligence software that is broken down by month. So I created a "calculated column" and added the following sql statement:

Case 
When [vdvVoucher].[PostDate] BETWEEN '2015-01-01T00:00:00' AND '2015-01-31T23:00:00'
then 'January'
Else
Case 
When [vdvVoucher].[PostDate] BETWEEN '2015-02-01T00:00:00' AND '2015-02-28T23:00:00'
then 'February'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-03-01T00:00:00' AND '2015-03-31T23:00:00'
then 'March'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-04-01T00:00:00' AND '2015-04-30T23:00:00'
then 'April'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-05-01T00:00:00' AND '2015-05-31T23:00:00'
then 'May'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-06-01T00:00:00' AND '2015-06-30T23:00:00'
then 'June'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-07-01T00:00:00' AND '2015-07-31T23:00:00'
then 'July'
Else
Case 
When [vdvVoucher].[PostDate] BETWEEN '2015-08-01T00:00:00' AND '2015-08-31T23:00:00'
then 'August'
Else 
Case 
When [vdvVoucher].[PostDate] BETWEEN '2015-09-01T00:00:00' AND '2015-09-30T23:00:00'
then 'September'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-10-01T00:00:00' AND '2015-10-31T23:00:00'
then 'October'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-11-01T00:00:00' AND '2015-11-30T23:00:00'
then 'November'
Else
Case
When [vdvVoucher].[PostDate] BETWEEN '2015-12-01T00:00:00' AND '2015-12-31T23:00:00'
then 'December'
End
END
End
End
End
End
End
End
End
End
End
End

Open in new window


I get the following error: Case expressions may only be nested to level 10.

Please advise.
Comment
Watch Question
EE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013
Commented:
This problem has been solved!
Unlock 2 Answers and 2 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE