语句
select * from mat_out where convert(char(10),datetime_out,121) <= '2005-05-02'既然 datetime_out 字段是datetime类型,不用转换成char()再比较,直接写成:
select * from mat_out where datetime_out <= '2005-05-02'可以利用datetime_out字段上建立的索引(如果建了索引的话)。至于两条SQL执行效率的差异,扔查询分析器里看看执行计划就知道孰快孰慢了。
select * from mat_out where convert(char(10),datetime_out,121) <= '2005-05-02'既然 datetime_out 字段是datetime类型,不用转换成char()再比较,直接写成:
select * from mat_out where datetime_out <= '2005-05-02'可以利用datetime_out字段上建立的索引(如果建了索引的话)。至于两条SQL执行效率的差异,扔查询分析器里看看执行计划就知道孰快孰慢了。
能直接比较,没有必要先转换成字符型再比较select * from mat_out where datetime_out <= '2005-05-02'
个人认为虽然没有进行转换,sql server还是进行了隐形的转换了.datetime型和char还是大不同地.
在查询分析器里,框选到你要的SQL,点Ctrl+L