表 kp
id ys  syrq 
1  2   2008-08-08
2  3   2008-09-01
3  33  2008-08-11 
想通过SQL语句实现把字段日期(syrq)+字段月份(月份)相加 , 显示一个新的日期字段
 使用 SELECT dateadd(m,(select ys from kp),(select syrq  from kp)) as 新日期 这个语句只能表里有一条数据,多了就报错了,哪个高手能帮忙指点一下么

解决方案 »

  1.   

    --> --> (Andy)生成测试数据 2008-10-19
    Set Nocount On
    declare @kp table([id] int,[ys] int,[syrq] Datetime)
    Insert @kp
    select 1,2,'2008-08-08' union all
    select 2,3,'2008-09-01' union all
    select 3,33,'2008-08-11'
     
    Select id,Dateadd(month,ys,syrq) As syrq from @kp/*
    id          syrq
    ----------- -----------------------
    1           2008-10-08 00:00:00.000
    2           2008-12-01 00:00:00.000
    3           2011-05-11 00:00:00.000
    */
      

  2.   

    Select Dateadd(month,cast(ys as int),syrq) As 新日期 from kp
      

  3.   

    SELECT dateadd(m, ys ,syrq  ) as 新日期  from kp