select * from 表 where YY+'-'+MM between '2002-9' and '2007-8'
create table dt(YY int,MM int) insert dt select 2002,9 union all select 2007,5 union all select 2007,8select YY,MM from dt where cast(YY as varchar)+'-'+cast(MM as varchar)>'2002-9' and cast(YY as varchar)+'-'+cast(MM as varchar)<'2007-8'YY MM ----------- ----------- 2007 5
select YY,MM from dt where cast(YY as varchar(4))+'-'+cast(MM as varchar(2))>'2002-9' and cast(YY as varchar(4))+'-'+cast(MM as varchar(2))<'2007-8'
首先:YY , MM为字符型字段 那么: select * from 表 where YY+'-'+MM between '2002-9' and '2007-8'
两个字段是字符型吗?如果是的话:select * from 表 where YY+'-'+MM between '2002-9' and '2007-8' 如果是数值型的,比较麻烦.要转换一下.
select * from 表 where YY+'-'+MM between '2002-9' and '2007-8'
insert dt select 2002,9
union all select 2007,5
union all select 2007,8select YY,MM from dt where
cast(YY as varchar)+'-'+cast(MM as varchar)>'2002-9' and cast(YY as varchar)+'-'+cast(MM as varchar)<'2007-8'YY MM
----------- -----------
2007 5
cast(YY as varchar(4))+'-'+cast(MM as varchar(2))>'2002-9' and cast(YY as varchar(4))+'-'+cast(MM as varchar(2))<'2007-8'
那么:
select * from 表 where YY+'-'+MM between '2002-9' and '2007-8'
如果是数值型的,比较麻烦.要转换一下.