問題:
Which method provides the best performance when removing the time portion from a datetime field in SQL Server?從 SQL Server 中的日期時間字段中刪除時間部分時,哪種方法可提供最佳性能?
a) select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
or要麼
b) select cast(convert(char(11), getdate(), 113) as datetime)
The second method does send a few more bytes either way but that might not be as important as the speed of the conversion.第二種方法確實會多發送幾個字節,但這可能不如轉換速度重要。
Both also appear to be very fast, but there might be a difference in speed when dealing with hundreds-of-thousands or more rows?兩者看起來也都非常快,但是在處理數十萬或更多行時速度可能會有所不同?
Also, is it possible that there are even better methods to get rid of the time portion of a datetime in SQL?另外,是否有更好的方法可以擺脫 SQL 中日期時間的時間部分?
解決方案:
參考一: https://en.stackoom.com/question/4wJ7參考二: https://stackoom.com/question/4wJ7