TRY:
select ID,articleDate from table1 where DATEPART(Year,articleDate )="&myYear&" and DATEPART(month,articleDate )="&myMonth&"

解决方案 »

  1.   

    declare @myyear varchar(10)
    declare @mymonth varchar(10)
    set @myyear = "&myYear&" 
    set @mymonth = "&myMonth&" 
    select ID,articleDate from table1 
     where DATEPART(yy,articleDate )=cast(@myyear as int)
       and DATEPART(mm,articleDate )=cast(@mymonth as int)
      

  2.   

    select ID,articleDate from table1 where year(articleDate)="&myYear&" and month(articleDate)="&myMonth&"
      

  3.   

    select ID,articleDate 
    from table1 
    where DATEPART(Year,articleDate )="&myYear&" 
    and DATEPART(month,articleDate )="&myMonth&"