Update [Table name] Set [Sex]=( Case when( Left( Right([ID Card],2),1)% 2 = 0) Then 'female' Else 'male' End)where Len([ID Card])= - and Left( Right([ID Card],2),1)<>'X'Update [Table name] Set [Sex]=( Case when( Right([ID Card],1)% 2 = 0) Then 'female' Else 'male' End)where Len([ID Card])= the and Right([ID Card],1)<>'X'Update [Table name] Set [Date of birth]=( Right( Left([ID Card],Ten),4)+'-'+right( Left([ID Card], A),2)+'-'+right( Left([ID Card], -),2))where Len([ID Card])= -Update [Table name] Set [Date of birth]=(' +'+right( Left([ID Card],8),2)+'-'+right( Left([ID Card],Ten),2)+'-'+right( Left([ID Card], A),2))where Len([ID Card])= theUpdate [Table name] Set [Age]= Year(getdate())-(cast( Left([Date of birth],4) as int))where [Date of birth]<>"'
#字符串格式化为日期格式SELECTDate_format ('19841201','%y-%m-%d') #---Know the date of birth for ageSELECTTimestampdiff ( Year, Date_format ('19841201','%y-%m-%d'), curdate ()); #截取身份证号中的年月日SELECTSUBSTR ('152824197810116015',7,8);SELECTSUBSTR ('152824781011601',7,6) #连接字符串SELECTCONCAT (' -',' A') #截取身份证号中的年月日1SELECT IF(LENGTH ('152824197810116015')= -, SUBSTR ('152824197810116015',7,8), CONCAT (' +', SUBSTR ('152824197810116015',7,6)) ; #截取身份证号中的年月日2SELECT IF(LENGTH ('152824781011601')= -, SUBSTR ('152824781011601',7,8), CONCAT (' +', SUBSTR ('152824781011601',7,6)) ; #根据身份证号计算年龄SELECTTimestampdiff ( Year, Date_format (IF(LENGTH ('152824781011601')= -, SUBSTR ('152824781011601',7,8), CONCAT (' +', SUBSTR ('152824781011601',7,6)) ),'%y-%m-%d'), curdate ());
Update @TSetnl= Case when Len(LTrim(RTrim(SFZ)))= - Then cast( Year(GetDate()) as int)- cast(substring(LTrim(RTrim(SFZ)),7,4) as int) Else cast( Year(GetDate()) as int)- cast(' +'+substring(LTrim(RTrim(SFZ)),7,2) as int)End
Analysis of the date of birth, gender, and age of SQL statements by ID card