select * from @temp b
left join
(
select csdate 
From cgshd 
)A
on cast(b.Myear+right('0'+cast(b.Mymonth as varchar),2)+'01' as datetime)=A.csdate

解决方案 »

  1.   

    select * from @temp b
    left join
    (
    select csdate  
    From cgshd 
    )A
    on b.Myear=year(csdate) and b.Mymonth=month(A.csdate)
      

  2.   

    干嘛不这样?
    select * from @temp b
    left join
    (
    select csdate 
    From cgshd 
    )A
    on year(A.csdate)=B.myear and month(A.csdate)=b.mymonth
      

  3.   

    昨天的问题搞定了。 谢谢你的提示。我用了临时表.
    select * into #temp(
    ...
    )然后select gysbh from
    ytgyszlb
    where gysbh in (select gysbh #temp)
    就这样做的.