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
 Transact-SQL (2000)
 Data Archive

Author  Topic 

aiman
Starting Member

18 Posts

Posted - 2007-06-21 : 01:30:26
I am going to Archive data for before 6th (1st Date to last 30/31th date) Month
My Query is like:--

Declare @@DateTime DateTime,
Set @@DateTime= GetDate()-?????? --[before 6th Mongtt]
Select * from TableName

where DateTime>@@DateTime and DateTime<@@DateTime

Please Help with a standard way how can i handle this DateTime

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-21 : 01:37:15
quote:
I am going to Archive data for before 6th (1st Date to last 30/31th date) Month

what do you mean by this ?

Assuming today is June 21, what is the expected result ?


KH

Go to Top of Page

aiman
Starting Member

18 Posts

Posted - 2007-06-21 : 01:47:02
Yes Today is 21th June , but i want to Collect Data For 1th Dec to 31th Dec 2006 and next 21th July will collect data for 1st january to 31th january
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-21 : 01:57:25
[code]SELECT today = GETDATE(),
start_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 6, 0),
end_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 5, -1)[/code]


KH

Go to Top of Page

aiman
Starting Member

18 Posts

Posted - 2007-06-21 : 02:22:51
Thank you lots..
Go to Top of Page

aiman
Starting Member

18 Posts

Posted - 2007-06-22 : 13:17:09
SELECT today = GETDATE(),
start_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 6, 0),
end_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 5, -1)


THis result give me one day less data.GetDate= 2007-06-22 23:15:02.013 start_date =2006-12-01 00:00:00.000 end_date=2006-12-31 00:00:00.000
But I need like end_date=2006-12-31 23:59:59.000...
Really sorry for this query again!!!!
Go to Top of Page
   

- Advertisement -