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

How to stop a loop early with break statements in ms sql server?

564


What does the automatic recovery do?

572


What is snapshot report?

129


What is right outer join in sql server joins?

686


How dts is used to extract, transform and consolidate data?

592






What is sql injection and why is it a problem? : sql server security

563


what are the steps you will take to improve performance of a poor performing query? : Sql server database administration

530


What are the steps to process a single select statement?

507


How to set a database state to offline in ms sql server?

534


What is explicit mode in sql server?

530


How data can be copied from one table to another table?

507


What is transactional replication?

555


What is database mirroring?

561


What is check constraint in sql server?

519


What is the difference between the 2 operating modes of database mirroring?

572