CAST(DATETIME AS DATE)over WHERE子句 [英] CAST(DATETIME AS DATE) over WHERE clause

查看:673
本文介绍了CAST(DATETIME AS DATE)over WHERE子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是SQL Server 2012,我想知道我是否写了句子:

I'm using SQL Server 2012 and I would like to know if I write the sentence:

SELECT MyDateTimeColumn 
FROM MyTable
WHERE CAST(MyDateTimeColumn AS DATE) = '2014-07-09'

是一个较慢的方式来修剪DATETIME列的时间,我已经搜索,但我找不到任何关于这个严格的句子,我不知道如何显示关于耗时的impresive统计数据转换/探测它自己。

is a slower way to trim the time over DATETIME columns, I have searched but I can't find anything about this strict sentence and I don't know how to show that impresive statistics about time consuming cast/convert to probe it myself.

推荐答案

在SQL 2008+, CAST(foo AS date)是可吞噬的,以及一些其他的操作。查看sqlfiddle中的执行计划。

In SQL 2008+, CAST(foo AS date) is sargable, along with a few other manipulations. Look at the execution plans in the sqlfiddle.

SQL谜语示范

SQL Fiddle Demo

这篇关于CAST(DATETIME AS DATE)over WHERE子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆