请教高手:以下语句为什么没有结果?
select a.id,a.itemname,a.status,a.person.a.thisyear 
from  a,b
where charindex(b.name,a.person)>0 and
      charindex(a.thisyear,cast(b.times as varchar(10)))>0 and b.uid=14 and a.id>0

解决方案 »

  1.   

     varchar(10)改成nvarchar(10)看看
      

  2.   

    charindex(a.thisyear,cast(b.times as varchar(10)))>0 有错。a.thisyear='2011'
    b.shenbtime 为年-月-日 (比如2011-01-03)格式
    怎样写b.shenbtime 包含 a.thisyear的条件?是用charindex()吗?
      

  3.   

    这样写a.thisyear=year(b.shenbtime)
    select year('2011-01-03')
    /*
    2011
    */
      

  4.   

    select datepart(day,getdate())获取日,select datepart(month,getdate())月,select datepart(year,getdate())年,等等