有一表 (Table1)如下:
Type (vchar), TheDate(DateTime)
"生日",       1979-1-21
"其它",       2005-1-21求一SQL,列出   Type <> '生日' 并且TheDate = 今天 的数据 和 Type = "生日"TheDate 的月和日等于今天的月和日的SQL.
如果是今天查询的话,2条记录应该全部查询到。

解决方案 »

  1.   

    declare @Birthday Datetime,@sToday varchar(10),@sBirth varchar(10)
    set @Birthday = '2004-01-21'
    set @sToday = (select cast(month(getdate()) as varchar(10)) + cast(day(getDate()) as varchar(10)) as Today)
    set @sBirth = (select cast(month(@Birthday) as varchar(10)) + cast(day(@Birthday) as varchar(10)) as Birthday)
    if @sToday = @sBirth
    select 'Today is your Birthday!'
    else
    select 'Today is not your Birthday!' -------------------------------------
    呵呵,up一下
      

  2.   

    dtToday
    dtMoon
    dtDay
    select * from Table1 
    where (Type <> '生日' and TheDate = :dtToday  ) or  (Type = "生日" and moon(Thedate)=:dtmoon and day(theDay)=:dtDay)呵呵,我不够专业.
      

  3.   

    --测试
    --测试数据
    Create Table T_Test (T_Name varchar(20),Type varchar(20),TheDate DateTime)
    insert T_Test select 'GaoLei','生日','1979-1-21'
    union  all select 'ZhangSan','其他','2005-1-21'
    union  all select 'LiSi','UnKown','2001-5-5'
    union all Select 'WangWu','生日','1981-2-5'select * from T_Test where 
    (type <> '生日' and DateDiff(Day,TheDate,GetDate()) = 0) 
    or 
    (Type = '生日' and
     month(TheDate) = month(GetDate())
     and Day(TheDate) = Day(GetDate())
    )
    Drop Table T_Test--测试结果
    T_Name   Type      TheDate
    GaoLei 生日 1979-01-21 00:00:00.000
    ZhangSan 其他 2005-01-21 00:00:00.000
      

  4.   

    select * from table1 where (thedate=getdate()  and type='生日') or
    (type='生日' and month(theday)=month(getdate()) and day(theday)=day(getdate()))