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

How global temporary tables are represented and its scope?

728


How efficient you are in oracle and SQL server?

821


What is oltp (online transaction processing)?

753


Can you leave a union at any time?

783


Which trace flags are enabled in sql server?

684


What is the command to change the recovery model?

774


Explain error handling in ssis?

768


What happens when the SQL Azure database reaches Max Size?

104


what is package and it uses and how can u call a package

1783


What is the maximum number of index per table?

775


What are the approximate numeric data types?

717


When a primary key constraint is included in a table, what other constraints does this imply?

779


your sql server is running out of disk space. You notice that there are several large files with ldf extensions what are these files? : Sql server administration

748


Any one plz send me SQL Server Developer/DBA resume for 4 years experience

2398


What is the difference between locking and multi-versioning?

737