I have 10 rows for today's date but my select statement 开发者_如何学Gobased on date dosen't seem to work....
SELECT Id,WirelessId,RegNo,DriverName1,MobileNo1,DriverName2,MobileNo1 from
DailySchedule where IsDeleted=0 and CreatedDate='2010-05-28'
Any suggestion...
Only if the dates assigned to them are midnight today. It might be better to do:
CreatedDate BETWEEN '2010-05-28 00:00' AND '2010-05-29 00:00'
If you want all the entries for May 28th I would do
and CreatedDate >='20100528'
and CreatedDate < '20100529'
Notice the safe ISO format (YYYYMMDD) no dashes
Also take a look at How Does Between Work With Dates In SQL Server? to see why between can not give you all the results you want
Assuming that CreatedDate is a datetime or a date, I don't see what's wrong with the syntax of the where clause. Maybe the IsDeleted field for those columns is actually NULL? (Or non-zero, at any rate.)
Edit: what Dave says, or DATE(CreatedDate) = '2010-05-28'
I'd check to see the type of the CreatedDate column and make sure that the string you're passing is being converted to a date properly.
When you say you 'have' 10 rows, is that confirmed visually or with a query executed in a console?
Not enough info to go on but I suspect that your dates have a time component and so don't match the string exactly.
Try using:
datediff(day, CreatedDate, '28-may-2010')) = 0
SELECT Id,WirelessId,RegNo,DriverName1,MobileNo1,DriverName2,MobileNo1 from
DailySchedule where IsDeleted=0 and date_format(CreatedDate, "%Y-%m-%d")='2010-05-28'
This should work too
select Id,
WirelessId,
RegNo,
DriverName1,
MobileNo1,
DriverName2,
MobileNo1
from DailySchedule
where IsDeleted=0
and CONVERT(varchar,CreatedDate,101) ='05/28/2010'
精彩评论