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 is master database? : SQL Server Architecture

525


What are the 10 characteristics of data quality?

527


Where do you find the default Index fill factor and how to change it?

597


How to return the top 5 rows from a select query in ms sql server?

586


You want to implement the one-to-one relationship while designing tables. How would you do it?

525






Where views are stored in sql server?

557


What are the different index configurations a table can have?

507


What are null values in ms sql server?

558


Disadvantages of the indexes?

587


Can sql server 2016 run on windows 7?

500


How to filter out duplications in the returning rows in ms sql server?

634


Can I use sql azure as a backup with log shipping or database mirroring?

136


Can binary strings be used in arithmetical operations?

522


when you create a database how is it stored? : Sql server database administration

489


Explain cursor as data base object?

572