Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want query between from date and to date.

Bur,i am getting error when i use below query.

I want to get result from date beteen "Given date and Max Date" and
To Date between "Given date and Max Date"

How to write Query or form the query...?

See my sample query
-------------------
SQL
select * FROM (
  SELECT datefrom AS datefrm, *
  FROM LM_TblLeaveapply
  WHERE datefrom between '2011-10-24' and (select Max(datefrom) from LM_TblLeaveapply)
) t1
FULL OUTER JOIN
 (
 SELECT dateto AS datto, *
  FROM LM_TblLeaveapply
  where dateto between '2011-10-24' and (select Max(dateto) from LM_TblLeaveapply)
) t2



sample data :

EmpId DateFrom DateTo
101 20-10-2010 20-10-2010
101 21-10-2010 21-10-2010
101 22-10-2010 22-10-2010
101 23-10-2010 23-10-2010
24-10-2011 24-10-2011
25-10-2011 25-10-2011
23-05-2012 23-05-2012
Posted
Updated 10-May-12 22:35pm
v2
Comments
Bernhard Hiller 11-May-12 4:39am    
1. Are your sample data ok? The last three lines do not have an EmpID value.
2. Could you describe in plain English what you want to achieve?

1 solution

The Error in Query is

You are making use of a join query so u have to make a common key of t1 and t2 in on condition

example.

SQL
select t1.*,t2.* FROM (
  SELECT datefrom AS datefrm, *
  FROM LM_TblLeaveapply
  WHERE datefrom between '2010-10-19' and (select Max(datefrom) from LM_TblLeaveapply)
) t1
FULL OUTER JOIN
 (
 SELECT dateto AS datto, *
  FROM LM_TblLeaveapply
  where dateto between '2010-10-19' and (select Max(dateto) from LM_TblLeaveapply)
) t2 on t1.empid = t2.empid


This is to run this query. but still dont know what u want as result.
 
Share this answer
 

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