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 2000 Forums
 SQL Server Development (2000)
 Populate Months Data

Author  Topic 

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2008-10-28 : 10:32:42
I currently populate a tbl with the current months figures using the following date range
WHERE DATEADD(mm,DATEDIFF(mm,0,[Date]),0)=DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
I have tried evry thing to populate 2 months worth of data into this table and I dont seem to be able to get my head round the changes needed. Any help would be grateful.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-28 : 10:41:53
[code]WHERE [Date]>DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
AND [Date]<DATEADD(mm,DATEDIFF(mm,0,GETDATE())+2,0)
[/code]
Go to Top of Page

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-28 : 10:44:49
Or
WHERE DATEDIFF(mm,[DATE],GETDATE()) = 2
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-29 : 08:10:14
quote:
Originally posted by hanbingl

Or
WHERE DATEDIFF(mm,[DATE],GETDATE()) = 2



Index wont be used if date column has it
Better approach is to use the approach Visakh suggested

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -