Microsoft
Software
Hardware
Network
Question : Need to get previous months in SQL Server
Yes, it's me again... another in a long line of questions.
I have this SQL:
SELECT month, funding_stoplight, funding_desc
FROM stoplight_listing
WHERE month = datepart(month,getDate()) AND year = datepart(year,getDate()) AND pid = 'TEST';
which works fine for what I need... the status of the current month.
Now the client wants me to get the status of the "PREVIOUS" months...
Things to consider...
If a project just starts, there are no previous months...
if we're in month 1 or 2 there's only going to be at max, 1 or 2 months previous.
If we span years... how do I calculate for that... considering a project could start Jan 1, XXXX
I think that covers it.
The return values for the ABOVE SQL is:
Month Stoplight Description
7 Y Some text...
I want to display the previous 3 months:
So it could be:
6 G All is good
5 R All is bad
4 Y All is not so bad....
Do I need separate SQL Statements or can I accomplish it with on SQL?
Thanks, all,
Peter
Answer : Need to get previous months in SQL Server
you should better have the complete date in a column instead of separated columns for year and month...
that way you may have a query with "date BETWEEN getDate() AND DATEADD(MONTH, -3, getDate())"
Random Solutions
net share system error 5 acces denied
Utilizing array gleamed from GetRows method in Access VBA
Symantec Endpoint Protection - SID 23615 HTTPS Tidserv Request 2 Detected
Deploy application using GPO win 2008 R2
Cisco 2950 Vlan for Voice
Opera Version 10.60 page cache(!?) problem
Could Linkserver provide me DB schema?
Multiple Stored Procedures in a single transaction
Crystal Reports Xi - Sorting a CrossTab Report by a Summary Field
HTC Touch 3G: How can I really upgrade WM6.1 to WM6.5 and/or porting to latest Android?