ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
How will u get 5 years back record?
 Question Submitted By :: Senthilsjc
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How will u get 5 years back record?
Answer
# 1
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 ?    4 Yes 0 No
Muhammadrashidmughal
 
  Re: How will u get 5 years back record?
Answer
# 2
--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 ?    3 Yes 0 No
Chris Fauvel
 
 
 
  Re: How will u get 5 years back record?
Answer
# 3
--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
Chris Fauvel
 
  Re: How will u get 5 years back record?
Answer
# 4
select *
from table
where date between GETDATE()-(5*365) and GETDATE()
 
Is This Answer Correct ?    0 Yes 0 No
Krishna Mohan Thamisetty
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
What is de-normalization and when do you do it?  3
Hi Friends, I have a table in which there are thousands of records and in city field there is NULL value for all records now i want to change that null value with distinct values in each record say delhi, bihar, agra, jaipur etc, what will be the query for that????? its not possible to update thousands of records one by one. is there any alternative ...? Plz help ... its urgent Thanx in advance  1
How to Check Whether a Global Temporary Exists in a SQL Database or not?  2
Difference Between varchar and nvarchar datatype? Satyam2
How to retrieve duplicate rows in a table? How to delete the duplicate entries in a table? Leo-Technologies12
can primery key be a non clustered index?  8
How do you use DBCC statements to monitor various aspects of a SQL server installation?  1
Differences between functions and stored procedures? 247Customer6
How to retrieve data from log files in SQL SERVER ?????  1
What are tasks? Wipro1
Can store procedure call by user define function in SQL server? HCL6
How do I compare two values when one value(data type) is char and the other is an integer?  3
why cluster and non clusterindex are used in sqlserver 2000? explain with example  1
What is ACID Property of Transaction?  4
What is the difference between local table and global table Polaris1
What are the different ways of moving data/databases between servers and databases in SQL Server?  1
how insert selected column only ? Robert-Half2
Wht is Stuff in sql ser  1
what is maximum size of temp db? iSoft4
Please give me queries for the following 1. To get the count of duplicate records. 2. A query to delete the duplicate records. 247Customer3
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com