1

I have a query with a column received and the value 2014-02-13 19:34:00. I fetch the date alone using DATE(received) and value is 2014-02-13

In MySQL I use the following query:

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

How to generate same value in SQL Server?

4

2 回答 2

4

在 SQL Server 中使用cast或。是 ANSI 标准。是 SqlServer 特定的convertCastConvert

 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);
于 2015-02-03T12:58:26.853 回答
0

如果您使用的是 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'))
于 2015-02-03T13:27:21.053 回答