Solved

Days in Month function embedded in query

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rebooting Witness SQL Server 2 24
Copy data to New Year 9 29
Logical Operator should return Integer value in SSIS 9 34
UPDATE JOIN multiple tables 5 16
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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

740 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