Now I want records between two dates.
I wrote my query as written below
SELECT * FROM mytable WHERE dtcreated>=fromdate AND dtcreated<=todate
This query work fine when fromdate and ToDate are of same month. i.e if fromDate =1/1/2011
and todate is 1/31/2011 it will work fine
But if fromdate is 1/1/2011 and todate is 2/1/2011 then no records will be returned.
Please give me solution of it


Suthish NairRank #92 · 22.8K reputationPosted Feb 7, 2011, 9:28 AM EST
Raju KatareRank #1,971 · 742 reputationPosted Feb 7, 2011, 7:49 PM EST
Hi Markand
use following query you will get desired result
SELECT * FROM mytable WHERE
convert(varchar,dtcreated,112)>=convert(varchar,fromdate ,112)
AND
convert(varchar,dtcreated,112)<=convert(varchar,todate,112)
Suthish NairRank #92 · 22.8K reputationPosted Feb 8, 2011, 8:33 AM EST
Raju KatareRank #1,971 · 742 reputationPosted Feb 8, 2011, 6:46 PM EST
Let me know that have you got the output?