Solved

Need to create a monthly report and need help with how to get dates or # of days in a month

Posted on 2008-10-10
1
151 Views
Last Modified: 2012-05-05
I need to run a sql query either the first day of the month and look at the previous month or run the last day of the month and look for all days in the current month.
How would I code this?
This is what we are doing now.
WHERE     (Incident.CreatedDateTime >= GETDATE() - 30)
we determine the number of days in the month and run it on the first day of the month manually.
We would like to automate this.
0
Comment
Question by:FLPeople
1 Comment
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 125 total points
ID: 22689190
subtract a month, not a number of days.  Use SQL's DateAdd to do so.

WHERE     (Incident.CreatedDateTime >= DateAdd(m, -1, GETDATE() ) 

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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