Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
dear sir/ma'am

here is my table=h_leave

date1 date2 hkey
07/11/2013 10/11/2013 1
10/11/2013 11/11/2013 2
15/11/2013 17/11/2013 3

i want that if i fill an application at 09/11/2013 then from database the checking is occur that is any range find
as in 09/11/2013
07/11/2013 10/11/2013
find

so the answer is
date1 date2 hkey
07/11/2013 10/11/2013 1

how such an answer i got
Posted
Updated 17-Jun-13 17:30pm
v3

1 solution

Wow. Several attempts later, based on how completely lost you were, try this:

select date1, date2, hkey from h_leave where date1 >= @date and date2 <= @date

Replace @date with the date you're checking, either as a param in a proc, or using a paramaterized query.
 
Share this answer
 
v3
Comments
ankur789 17-Jun-13 23:09pm    
sir same answer i found
date1
07/11/2013
10/11/2013
15/11/2013
Christian Graus 17-Jun-13 23:14pm    
I am not sure exactly what you wanted. Did you want to filter on date2 both times ? If so, change my code to do that.
ankur789 17-Jun-13 23:20pm    
sir i select 09/11/2013
then your query will be
select date1 from h_leave
where (date1 between '2013/11/09' and '2013/11/09')
union all
select date2 from h_leave
where (date2 between '2013/11/09' and '2013/11/09')


but please check in my table there is a row between this range the row consists 07/11/2013 as date1 and 10/11/2013 as date2

but fromyour query the answer i got as null
Christian Graus 17-Jun-13 23:26pm    
If you don't know enough about SQL to read my SQL and understand it, you should not be doing this. If you want to filter on date2 in both queries, you need this:

select date1 from h_leave
where (date2 between '2013/11/09' and '2013/11/09')
union all
select date2 from h_leave
where (date2 between '2013/11/09' and '2013/11/09')
ankur789 17-Jun-13 23:22pm    
while the answer should be
07/11/2013
10/11/2013

because 9 is in this range

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