Solved

Days in Month function embedded in query

Posted on 2012-03-17
1
360 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now