我试图在SQL 2012中从我们的Avaya数据库中检索电话,但我似乎无法正确获取代码上的日期。
string query = "Select COUNT(Taskid) OVER() Taskid, a.Name, b.Restaurant, a.City, c.[Postal Code], a.[Open Date], a.POSSystem, d.Count(Taskid) FROM Stores a, tblConcepts b, tblStates c, tblAssignedTasks d WHERE a.ConceptID = b.Restaurantid AND a.State = c.Stateid AND a.[Open Date] >= cast(cast(getdate() as date) as datetime AND b.Restaurantid = d.StoreID AND d.Complete = 'True' GROUP BY d.StoreID)";
这是我的查询字符串
cmdCalls = String.Format("SELECT * FROM dbo.tblCallList WHERE CreateDate > cast('" & DateYesterday & "' as date)")
我似乎无法从数据库中提取我需要的数据,它确实减去了日期变量的天数,但问题是它在查询中使用天数作为月份,它显示了来自数据库的所有记录月而不是白天
数据库上的日期格式是' 2017-06-08 12:04 :: 00:000'例如
答案 0 :(得分:2)
使用数据库中的当前日期:
SELECT *
FROM dbo.tblCallList
WHERE CreateDate >= CAST(getdate() as date);