How will u get 5 years back record?

Answer Posted / chris fauvel

--crap made a booboo
--corrected code here
--Both use the dateadd function provided by t-sql, I'm sure
oracle and others have similar functions

--this way is a little slower and costlier
select *
FROM sys.tables
where modify_date between dateadd(yy, -5, getdate() ) and
getdate()

--this way is faster and less costly, by not doing the same
--function for every row.
declare @now datetime
, @then datetime
select @now = convert(datetime, convert(varchar, getdate()))
, @then = dateadd(yy, -5, @now)

Select *
from sys.tables
where modify_date between @then and @now

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is scan table/view and seek table/view when its occurs? : sql server database administration

768


What is the difference between deallocate cursor and close cursor?

938


Explain what is sql server english query?

756


What is index fragmentation in ms sql server?

790


How do triggers work?

713


What is triggers and stored procedures?

709


Determine when to use stored procedure to complete sql server tasks?

738


What is serializable?

845


hi i am working as a testengineer , so i want to no the backend data base connection can any one tell mwe in detail

1988


What is the difference between ddl and dml?

805


What are translations and its use? : sql server analysis services, ssas

818


Mention the differences between substr and charindex in sql server.

728


What is raid? : SQL Server Architecture

826


How to list all user defined functions in the current database?

717


What do you mean by a Composite primary key?

775