当前位置: 代码迷 >> PB >> 关于年龄的计算~小弟我是初学者,请大哥们帮帮小弟我!
  详细解决方案

关于年龄的计算~小弟我是初学者,请大哥们帮帮小弟我!

热度:45   发布时间:2016-04-29 08:47:16.0
关于年龄的计算~~~~~~~~~我是菜鸟,请大哥们帮帮我!!!
在Compute Expression里怎么写表达式,实现小于2岁的显示年龄是几个月????
year(today()) - year(date( csny )) 这个是我现在写的~~~

------解决方案--------------------
直接用数据窗口的数据源来实现比较简单,参照下面的例子:
SQL code
declare @t table(a int, b datetime)insert into @tselect 1, '2001-11-01' union allselect 2, '2003-01-21' union allselect 3, '2004-09-12' union allselect 4, '2009-04-01' union allselect 5, '2010-12-14' union allselect 6, '2011-01-12' select     a,     case sign(DATEDIFF(month, b, getdate()) - 24)     when -1 then cast(DATEDIFF(month, b, getdate()) as varchar(4)) + '月'    else cast(DATEDIFF(year, b, getdate()) as varchar(4)) + '岁' end as '年纪'from @t/*结果(所影响的行数为 6 行)a           年纪     ----------- ------ 1           10岁2           8岁3           7岁4           23月5           3月6           2月(所影响的行数为 6 行)*/
  相关解决方案