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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Current Month

Author  Topic 

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2009-01-22 : 03:33:20
Good Morning
I was wondering if any one can help with the problem I am faced with I currently have a tbl that has the current months data in I have been requested to get the last 6 day of the previous month in there as well. Every thing I have found on the web does not work. If I can add it to my current code it would be great?? My current month code reads WHERE DATEADD(mm,DATEDIFF(mm,0,DC.[Date]),0)=DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)



Whitmoj
If I have inspired one person today then my job is done.

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-22 : 04:10:18
Hi Try Thiss

select * from urtable where datediff(mm,dc.date,getdate())=0 or datediff(d,dc.date,dateadd(d,-datepart(d,getdate()),getdate()))<6

Jai Krishna
Go to Top of Page

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2009-01-22 : 04:22:13
This works great the only issue is in my db where my Date is It goes to 2012 so its returning all my dates. How can I solve this??

Whitmoj
If I have inspired one person today then my job is done.
Go to Top of Page

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2009-01-22 : 04:24:44
I have sorted it
Many thanks Jai

James

Whitmoj
If I have inspired one person today then my job is done.
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-22 : 04:29:22
Welcome

Jai Krishna
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-22 : 04:31:12
[code]DECLARE @FromDate DATETIME,
@ToDate DATETIME

SELECT @FromDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '18991226'),
@ToDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '19000201')

SELECT @FromDate,
@ToDate

SELECT *
FROM Table1
WHERE Col1 >= @FromDate
AND Col1 < @ToDate[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -