I want to select the value between the date
Table1
Code Period Datefrom dateto Value
001 07/2011 01/07/2009 10/07/2009 100
211 07/2009 01/07/2009 05/07/2009 200
From the above table i want to check the date between datefrom and dateto, if the date is in between or equal to datefrom dateto means, it should return the value of the empcode
Tried Query
SELECT Value
FROM table1
Where Period = '07/2009'
and Code = '211'
and Cast('02/07/2009' as Datetime) between datefrom and dateto
Expected Output:
code value
211 200
The above query is showing null value, it should return 200.
What wrong in my query?
Your
Cast('02/07/2009' as Datetime)brings to you 7th February by defaultuse this instead
BUT
You, probably have to convert
datefromanddatetocolumns too if they are of varchar type.