在sql中如何获取本月过生日人员的具体生日日期
如: 出生日期是 1987-09-09
得出:今年生日日期是 2003-09-09
需在sql查询语句中查出本月内生日人员的生日日期
各位请帮帮忙!SQL

解决方案 »

  1.   

    datepart(m,生日日期)=datepart(m,getdate())
      

  2.   

    select convert(varchar,day(出生日期)))
    from 人员表
    where month(出生日期)=month(getdate())
      

  3.   

    select dateadd(mm,datediff(month,生日,getdate()),生日)
    from 表 
    where datediff(month,生日,getdate())=0
      

  4.   


    --1987-09-18 
    select * from TB where month(生日)=9 and day(生日)=18
      

  5.   

    因为我这个条件是在后台拼接的,所以说如果这个生日日期字段能在sql语句中直接查询出来,就好办多了。
    要是实在不好实现的话,有没有什么办法可以让在后台拼接出 当前时间段的月份期间和日区间 跟 出生日期的月份区间和日区间 做为对比条件呢?
      

  6.   


    --9月份
    select * from TB where month(生日)=9
    --18号这一天
    select * from TB where day(生日)=18
    --区间 9-11月份
    select * from TB where month(生日)>=9 and month(生日)<=11
      

  7.   

    select *
    from 人员表
    where convert(varchar(10),录入日期,120)>='2013-01-01' --随意开始日期
    and convert(varchar(10),录入日期,120)<='2013-07-10' --随意结束日期
    and month(出生日期)>=month('2013-01-01')
    and month(出生日期)<=month('2013-07-10')
      

  8.   

    你的getdate()的结果是本月还是上月?
      

  9.   


    select dateadd(yy,datediff(yy,' 1987-09-09',getdate()),'1987-09-09')
      

  10.   


    select * from employee where month(birthday)=month(getdate())
      

  11.   

    select dateadd(mm,datediff(month,生日,getdate()),生日)
    from 表 
    where datediff(month,生日,getdate())=0
      

  12.   


    sql 里边的函数好多的赶脚 都没怎么用过
      

  13.   


    sql 里边的函数好多的赶脚 都没怎么用过
    参考http://msdn.microsoft.com/zh-cn/library/ms174077%28v=sql.100%29.aspx函数挺多,用用就记住了。 
      

  14.   


    sql 里边的函数好多的赶脚 都没怎么用过
    参考http://msdn.microsoft.com/zh-cn/library/ms174077%28v=sql.100%29.aspx函数挺多,用用就记住了。 thanks