在 SQL 服务器中单独生成 DATE 值

Generate DATE value alone in SQL Server

我有一个包含列 received 和值 2014-02-13 19:34:00 的查询。我使用 DATE(received) 单独获取日期,值为 2014-02-13

在 MySQL 中,我使用以下查询:

SELECT DATE(received) AS Mydate, status  
FROM Notification
WHERE project = 'proj001'  
GROUP BY Mydate 
ORDER BY received;

如何在 SQL 服务器中生成相同的值?

在 SQL 服务器中使用 castconvertCast 是 ANSI 标准。 Convert 是 SqlServer 特定的

 select cast(received as date),status FROM Notification   -- or convert(date,received)
 WHERE project='proj001'  
 GROUP BY cast(received as date),status 
 ORDER BY cast(received as date);

如果您使用的是 SQL Server 2008 及更高版本,则

SELECT CONVERT(date, '2014-02-13 19:34:00') 

如果您使用的是旧版本,则

SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, '2014-02-13 19:34:00'))