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