SELECT *, Age= datediff(yy,cast(case when substring(PersonalId,7,1) in ('1','2') /*若第7位不是'1'或'2'则表示是15位身份证编码规则*/ then substring(PersonalId,7,8) else '19' + substring(PersonalId,7,6) end as datetime),getdate()) FROM Student WHERE datediff(yy,cast(case when substring(PersonalId,7,1) in ('1','2') then substring(PersonalId,7,8) else '19' + substring(PersonalId,7,6) end as datetime),getdate()) <18