Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Days in Month function embedded in query

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

808 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