create table #temp( id int identity(1,1), name varchar(20), startYear int, startMonth int)
insert into #tempselect 'z','2010','12' union allselect 'e','2011','11' union allselect 'a','2011','2' union allselect 'b','2011','5' union allselect 'c','2011','10' union allselect 'd','2011','7'
--查询早于等于指定日期的数据declare @condition varchar(6)set @condition='201110'
select * from #temp Awhere (case when LEN(A.startMonth)=1 and A.startMonth!=0 then cast((CAST(startYear as varchar(4))+'0'+cast(A.startMonth as varchar(1))) as date) when LEN(A.startMonth)=2 then cast(CAST(startYear as varchar(4))+cast(A.startMonth as varchar(2)) as date) end) <=cast(@condition as date)