Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kweegly
Starting Member
7 Posts |
Posted - 2013-01-15 : 06:10:05
|
Hi Everyone,I have a field called IssueDate and would like to pull IssueDates from only the previous month but I can't seem to get it working. I use BETWEEN GETDATE() -7 AND GETDATE() to get the last 7 days but I don't know how to get the last month (not last rolling 30 days).Thanks for any help in advance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-15 : 06:34:35
|
[code]WHERE IssueDate >= dateadd(mm,datediff(mm,0,getdate())-1,0)and IssueDate < dateadd(mm,datediff(mm,0,getdate()),0)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2013-01-15 : 06:34:45
|
Here is an bad method to get that data. Put that in where condition.WHERE DATEPART(MONTH,IssueDates) = CASE WHEN DATEPART(MONTH,GETDATE())-1 = 0 THEN 12 ELSE DATEPART(MONTH,GETDATE())-1AND DATEPART(YEAR,IssueDates) = CASE WHEN DATEPART(MONTH,GETDATE())-1 = 0 THEN 12 ELSE DATEPART(YEAR,GETDATE())-1------------------------------------------------The answer is always no till than you don't ask. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|