Click here to Skip to main content
15,914,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually in my table i am filtering through From-date and to-date.for example
Tabel-LoginDetails
XML
userid|loginDate
sai   ||13/1/2012
jam   | 13/1/2012
sai   | 10/2/2012
sai   | 11/2/2012

Now i will pass three parameters Userid,FromDate,ToDate(sravi,13/1/2012,13/2/2012)

how to write sql query for the below result

now i shold get the records like below
<pre lang="vb">userid|loginDate
sai   ||13/1/2012
sai   | 10/2/2012
sai   | 11/2/2012</pre>
Posted

select userid,loginDate from LoginDetails where loginDate<=01/01/2013 and loginDate>=01/02/2013
 
Share this answer
 
Their are many ways of achieving this
1. Use of BETWEEN[^]
SQL
select userid,loginDate from tblname where loginDate BETWEEN FromDate AND ToDate

2. Simply compare the two dates with the specified one
SQL
select userid,loginDate from tblname where loginDate<=ToDate and loginDate>=FromDate


3. Use DATEDIFF()[^] function which returns an integer value i.e. count between two dates
 
Share this answer
 
Comments
ntitish 15-Jul-13 2:57am    
select * from logindetails where userid='sai' and logindate between '13/1/2012' and '13/2/2012'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900