Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How will u get 5 years back record?

Answers were Sorted based on User's Feedback



How will u get 5 years back record?..

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

How will u get 5 years back record?..

Answer / muhammadrashidmughal

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

How will u get 5 years back record?..

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

How will u get 5 years back record?..

Answer / tp

select * from table1 where date between dateadd(yy,-
5,getdate()) and getdate()

Is This Answer Correct ?    1 Yes 0 No

How will u get 5 years back record?..

Answer / krishna mohan thamisetty

select *
from table
where date between GETDATE()-(5*365) and GETDATE()

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL Server Interview Questions

What is page in sql server?

0 Answers  


what are batch in sql server?

2 Answers   Satyam,


If we drop a table, does it also drop related objects like constraints, indexes, columns, defaults, views, and stored procedures?

1 Answers  


How many types of system privileges are there, Can we add or delete privileges?

2 Answers  


What are the differences between DDL, DML and DCL in SQL?

0 Answers   ABB, Aspire, Infogain,


How to encrypt Strored Procedure in SQL SERVER?

0 Answers  


What is a linked server in sql server?

0 Answers  


what is datawarehouse?

0 Answers   Informatica,


Explain the relational database management system (rdbms)?

0 Answers  


What is a Join in SQL Server?

3 Answers  


What are the different types of sub-queries?

0 Answers  


Is it important for a database administrator to understand the operating system and file access?

0 Answers  


Categories