一个表(user)里面有个出生日期的字段(bortDate),记录如下:
姓名:     出生日期:张三       1977-08-18
李四       1982-10-12
王五       1985-12-15
查出在15天内生日的人员的记录

解决方案 »

  1.   

    adoquery1.sql.add('select * from [user] where 出生日期>=)'+#39+DateTostr(Date)+#39+' and 出生日期<='+#39+DateTostr(Date+15)+#39)
      

  2.   

    select * from user
    where bortDate>   dateadd(day,-15,getdate())
      

  3.   

    to  SiTwo(闻之笑)
    #39 代表是什么意思?
      

  4.   

    adoquery1.sql.text:='select * from user where '
        +'(DATEPART(month,getdate()+15)=DATEPART(month,bortDate)) and ('
        +''DATEPART(day,getdate()+15)=DATEPART(day,bortDate))'
      

  5.   

    select * from @T 
    where (case when (birthday>convert(varchar(10),getdate(),120)) 
    then datediff(day,convert(varchar(10),getdate()),birthday)
    else datediff(day,birthday,convert(varchar(10),getdate(),120)) 
    end)<=15
      

  6.   

    declare @T table (name varchar(20),birthday datetime)
    insert into @T
    select 
    '张三','1977-08-18'
    union all
    select
    '李四','1982-10-12'
    union all 
    select 
    '王五','1985-12-15'--上面建立测试表
    select * from @T 
    where (case when (birthday>convert(varchar(10),getdate(),120)) 
    then datediff(day,convert(varchar(10),getdate()),birthday)
    else datediff(day,birthday,convert(varchar(10),getdate(),120)) 
    end)<=15
      

  7.   

    select * from user
    where bortDate>   dateadd(day,-15,getdate()) and bortDate<   dateadd(day,15,getdate())
      

  8.   

    select * from user
    where datediff(day, getdate(), bortDate) <= 15