身份证号码识别性别
ALTER FUNCTION [dbo].[GetGenderByPeopleID]
(
@id VARCHAR(18)
)
RETURNS nchar(1)
AS
BEGIN
DECLARE @sex AS varchar(3),@gender AS nchar(1)
IF LEN(@id)>=15
begin
if len(@id)=18
begin
set @sex=substring(@id,15,3)
end
if len(@id)=15
begin
set @sex=substring(@id,13,3)
end
set @sex=CAST(@sex AS INT)
if @sex%2=0
begin
Set @gender='女'
end
else
begin
set @gender='男'
END
END
RETURN @gender
END