数据表:
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