Solved

Days in Month function embedded in query

Posted on 2012-03-17
1
373 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
[X]
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
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

Industry Leaders: 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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

635 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