Sybase中SQL关于时间的模糊查询,高手请进(急)!

表A
ID TIME
1 20100124
2 20100126
3 20100201
4 20100205
5 20100223

我的想法是用like(限定)实现查找到2010年2月的数据
select * from A where TIME like XXXX(不会实现如何用截取年月这两个段)
分少,回答正确后再给分了
限定用like

如果TIME是datetime数据类型:

select * from A where datepart(year,TIME) = 2101 and datepart(month,TIME) = 2
或者
select * from A where TIME between "2010-2-1" and "2010-2-28 23:59:29"

如果TIME是字符类型
select * from A where TIME between "20100201" and "20100228"
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-07-31
where TIME >='2010-2-1' and TIME <'2010-3-1'

或者

where year(TIME)=2010 and month(TIME)=2

-------------------------------------
时间类型转换为字符型用like 效率会低哦

如果TIME是datetime型的
where convert(varchar,TIME,112) like '201002%'

如果TIME是字符型的
where TIME like '201002%'
第2个回答  2010-08-06
select * from 表A where to_char(time,'YYYYMM') like '%201002%'
相似回答