what is a query to select records between two dates. [Resolved]

Posted by Sahaj.seema under Sql Server on 2/25/2010 | Views : 60306 | Status : [Member] | Replies : 3
I want to find the records from a table between two different dates.Eg.I want to find all the records from 1jan 2010 to 15 jan 2010.whts the query,tell me somebody
regads.




Responses

Posted by: Bubbly on: 2/26/2010 [Member] Bronze

Up
0
Down

Resolved
Hello,

You can create a stored procedure with from-date and to-date parameters

select colname1,colname2 from tablename where date between @frmdate and @todate


++
Thanks & Regards,
Deepika

Sahaj.seema, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 2/25/2010 [Member] Bronze

Up
0
Down
Try the following query

SELECT * FROM DATE_SAMPLE WHERE SAMPLE_DATE between '2003-04-09' AND '2003-04-10'



Also you can do like as follows

SELECT * FROM DATE_SAMPLE WHERE SAMPLE_DATE >= '2003-04-09' AND SAMPLE_DATE <= '2003-04-10'



Replace the exact format of your date time here and check

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Sahaj.seema, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajujrk on: 2/25/2010 [Member] Starter

Up
0
Down
Assume our Table structure is like below one:
EMPTAB

Name Designation Date_of_Joining
=======================================
Raju Programmer 12-10-2005
Abhishek Team Leader 13-11-2002
Arun Project Manager 14-05-2001
Kannan Programmer 15-06-2003

Here is your query to find the employee details who joined between '01-01-2001' to '30-12-2003'
[code]
SELECT Name,Desgination FROM emptab WHERE Date_of_Joining BETWEEN '01/01/2001' and '30/12/2003'
[/code]


Output of this above query is

Name Designation
======================
Abhishek Team Leader
Arun Project Manager
Kannan Programmer

Thanks & Regards

Rajkumar J

Sahaj.seema, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response