读书人

怎么最快的查询到指定月份的所有数据

发布时间: 2012-01-30 21:15:58 作者: rapoo

如何最快的查询到指定月份的所有数据?
数据表:
ID DATETIME
1 2006-10-2
2 2006-10-12
3 2006-11-22
4 2006-12-17

用什么方法可以最快查到2006-10的数据?

[解决办法]
select * from ta where convert(varchar(7),[datetime],120)= '2006-10 '
[解决办法]
--或者
select * from ta where year([datetime])=2006 and month([datetime])=10
[解决办法]
select * from tbName where convert(char(7), DATETIME, 120)= '2006-10 '
[解决办法]
这样就可以了
select * from TableName where convert(char(7), DateTime, 120)= '2006-10 '
[解决办法]
select * from tabName where datediff(month,dtTime, '2006-10-1 ') = 0

读书人网 >SQL Server

热点推荐