How will u get 5 years back record?
Answers were Sorted based on User's Feedback
Answer / 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 |
select *
from table
where date between '01/01/2003' and '12-31-2008'
or
today is 09-08-2008
select *
from table
where year(date)=year(getdate)-5 and month(date)= '08' and
day(date) ='09'
or
select *
from table
where date >='09-08-2003'
and date<='09-08-2008'
| Is This Answer Correct ? | 5 Yes | 1 No |
Answer / 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 |
Answer / krishna mohan thamisetty
select *
from table
where date between GETDATE()-(5*365) and GETDATE()
| Is This Answer Correct ? | 0 Yes | 1 No |
What is page in sql server?
what are batch in sql server?
If we drop a table, does it also drop related objects like constraints, indexes, columns, defaults, views, and stored procedures?
How many types of system privileges are there, Can we add or delete privileges?
What are the differences between DDL, DML and DCL in SQL?
0 Answers ABB, Aspire, Infogain,
How to encrypt Strored Procedure in SQL SERVER?
What is a linked server in sql server?
what is datawarehouse?
Explain the relational database management system (rdbms)?
What is a Join in SQL Server?
What are the different types of sub-queries?
Is it important for a database administrator to understand the operating system and file access?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)