Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Days in Month function embedded in query

Posted on 2012-03-17
1
Medium Priority
?
381 Views
Last Modified: 2012-03-17
I have a table that has budgeted values with Year/Month values. I need to get the daily values by dividing the monthly amounts by the days in the month.

Her is a sample of the data
YearMonth      BudgetMthAmtGas
2012/01      2427641
2012/02      2249955
2012/03      2382530
2012/04      2284998
2012/05      2340656

I would not think this would be all that hard but I need some help.
0
Comment
Question by:bbaldwin
1 Comment
 
LVL 2

Accepted Solution

by:
bbaldwin earned 0 total points
ID: 37733641
Figured out how to get it done without using a function.

select case when Right([YearMonth],2) in ('01', '03', '05', '07', '08', '10', '12') then 31
                  WHEN Right([YearMonth],2) IN ('04', '06', '09', '11') THEN 30
                        ELSE CASE WHEN (YEAR(convert(DATETIME,[YearMonth]+'/01')) % 4    = 0 AND
                                YEAR(convert(DATETIME,[YearMonth]+'/01')) % 100 != 0) OR
                               (YEAR(convert(DATETIME,[YearMonth]+'/01')) % 400  = 0)
                          THEN 29
                          ELSE 28
                END
            END as DaysInMonth
from cust_team_budget
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question