Avatar of isames
isames
 asked on

Sql Case Expression (Nested)

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.
Microsoft SQL Server 2008Microsoft SQL Server

Avatar of undefined
Last Comment
PortletPaul

8/22/2022 - Mon
SOLUTION
Mike Eghtebas

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
PortletPaul

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck