Table1
ID Month datefrom dateto reason
001 12/2011 01/12/2011 10/12/2011 Leave
001 12/2011 18/12/2011 25/12/2011 Holiday
.....
datefrom, dateto datatype is datetime
, datefrom & dateto format is (dd/mm/yyyy
)
Before inserting datefrom,dateto i want to check whether it is matching with datefrom and dateto from table
Tried Query (Before Inserting i am checking whether user entry date is matching with table)
SELECT * FROM table1
WHERE (Month = '01/2012') AND
(id = '001') and
Convert(Datetime, '01/12/2011', 103) between datefrom and dateto or
Convert(Datetime, '10/12/2011', 103) between datefrom and dateto
The above query is working if i select the date from 01/12/2011 to 10/12/2011, incase if i selecting the date from 31/11/2011 to 11/12/2011 means it is allowing to insert...
How to modify my query....
Need query Help