How will u get 5 years back record?

Answer Posted / chris fauvel

--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
dateadd(yy, -2, 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 ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different types of replication you can set up in sql server?

622


What are dml triggers and types of dml triggers?

630


What is factless fact table? : sql server analysis services, ssas

658


Define cursor locking

637


What are the differences between local and global temporary tables?

649






What is the maximum size of sql server database?

594


What is transaction server implicit?

604


How to get a list of columns using the "sys.columns" view in ms sql server?

644


How to access the inserted record of an event?

670


What is index, cluster index and nonclustered index?

596


Which are the important points to note when multilanguage data is stored in a table?

592


What is the boxing and unboxing concept in .net?

634


What is parameterized reports in ssrs ?

111


Can I disable or restrict ssrs export formats (rendering formats)?

116


What are commit and rollback in sql?

658