IdentityNumber 是身份证号
年龄:
FLOORDATEDIFFDY, substringb.IdentityNumber,7,4), GETDATE)) / 365.25) as '推荐人年龄',
15位的身份证计算年龄:
case when b.IdentityNumber IS null or b.IdentityNumber='' then '' when lenb.IdentityNumber)=18 and dbo.IsvalidIDCardb.IdentityNumber)=1 then CASTDATEDIFFYEAR, substringb.IdentityNumber,7,4), GETDATE)) AS nvarchar20)) when lenb.IdentityNumber)=15 and dbo.IsvalidIDCardb.IdentityNumber)=1 then CASTDATEDIFFYEAR,'19'+substringb.IdentityNumber,7,2), GETDATE)) AS nvarchar20)) else '' end as '推荐人年龄',
性别:
case when lenb.IdentityNumber)=18 and castsubstringb.IdentityNumber,17,1) as int)%2=1) or lenb.IdentityNumber)=15 and castrightb.IdentityNumber,1) as int)%2=1) then '男' when lenb.IdentityNumber)=18 and castsubstringb.IdentityNumber,17,1) as int)%2=0) or lenb.IdentityNumber)=15 and castrightb.IdentityNumber,1) as int)%2=0) then '女' else '' end as '推荐人性别',