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
How to stop a loop early with break statements in ms sql server?
What does the automatic recovery do?
What is snapshot report?
What is right outer join in sql server joins?
How dts is used to extract, transform and consolidate data?
What is sql injection and why is it a problem? : sql server security
what are the steps you will take to improve performance of a poor performing query? : Sql server database administration
What are the steps to process a single select statement?
How to set a database state to offline in ms sql server?
What is explicit mode in sql server?
How data can be copied from one table to another table?
What is transactional replication?
What is database mirroring?
What is check constraint in sql server?
What is the difference between the 2 operating modes of database mirroring?