SQL SERVER根据出生年月、性别、身份计算年龄、内退时间

时间:2021-09-01 00:37:00

SELECT     dbo.ygb.ygbm, dbo.ygb.ygxm, dbo.ygb.ygxb, dbo.ygb.ygmz, dbo.ygb.sfid, dbo.ygb.zzmm, dbo.ygb.ygsr, YEAR(GETDATE()) - YEAR(dbo.ygb.ygsr) AS ygnl,
                      dbo.ygb.gzsj, CASE WHEN ygxb = '1' THEN DATEDIFF(day, GETDATE(), DATEADD(year, 50, ygsr)) WHEN ygxb = '0' AND yglb = '*' THEN DATEDIFF(day, GETDATE(),
                       DATEADD(year, 45, ygsr)) WHEN ygxb = '0' AND yglb = '工人' THEN DATEDIFF(day, GETDATE(), DATEADD(year, 40, ygsr)) END AS ntts, dbo.ygb.byxx, dbo.ygb.ygxl,
                      dbo.xlb.xlmc, dbo.ygb.ygzc, dbo.zcb.zcmc, dbo.ygb.ygjn, dbo.jnb.jnmc, dbo.ygb.ygzw, dbo.zwb.zwmc, dbo.ygb.lxdh, dbo.ygb.gzgw, dbo.ygb.yglb, dbo.ygb.memo,
                      dbo.vw_ygqkb.qkmc, dbo.vw_ygqkb.tqts, dbo.vw_ygqkb.shjg
FROM         dbo.xlb INNER JOIN
                      dbo.ygb ON dbo.xlb.xlbm = dbo.ygb.ygxl INNER JOIN
                      dbo.zcb ON dbo.ygb.ygzc = dbo.zcb.zcbm INNER JOIN
                      dbo.jnb ON dbo.ygb.ygjn = dbo.jnb.jnbm INNER JOIN
                      dbo.zwb ON dbo.ygb.ygzw = dbo.zwb.zwbm LEFT OUTER JOIN
                      dbo.vw_ygqkb ON dbo.ygb.ygbm = dbo.vw_ygqkb.ygbm