我有我的Open Date
列此值:2017-6-14 AM 12:00:00
使用LEFT查詢不能
我想拿起剛剛日期(2017-6-14
)的一部分,所以我在查詢中使用LEFT()
。不幸的是,我的結果顯示的不僅僅是'2017-6-14'。
這是我所做的查詢。
Select a.Name, b.Restaurant, a.City, c.[Postal Code] as 'State',
LEFT(a.[Open Date],CHAIRINDEX(' ',a.[Open Date]-1)),
a.CO as 'T Date',
(SELECT Count(Taskid) FROM Tasks WHERE Complete = 'True' AND SID = a.ID GROUP BY SID) AS 'Tasks Complete',
(SELECT COUNT(Complete) FROM Tasks WHERE Complete = 'false' AND T_Date <= cast(cast(getdate() as date) as datetime) AND SID = a.ID GROUP BY SID) AS 'Tasks Overdue'
FROM Stores a
JOIN Concepts b ON a.ConceptID = b.R_id
JOIN States c ON a.State = c.Stateid WHERE a.[Open Date] >= cast(cast(getdate() as date) as datetime)
ORDER BY a.[Open Date] ASC
使用日期轉換或格式化函數。不要試圖採取約會的左邊部分。 https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql –
「不工作」不是描述性的。 –
你在使用什麼數據庫引擎? –