--定义身份证号码和原始身份证号码两个参数,如果身份证号码不是18和15位,我们就选择ysxx的身份证号码
USE [Das]
GO
/****** Object: UserDefinedFunction [dbo].[Getsfzhm] Script Date: 2020/11/24 10:17:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[Getsfzhm]
(
@sfzhm varchar(50), @ysxx varchar(200)
)
RETURNS varchar(18)
AS
BEGIN
declare @ret varchar (50)
declare @index int
if len(@sfzhm)=15 or len(@sfzhm)=18
begin
set @ret=@sfzhm
end
else
begin
--420122197507161617|吴任成|42011515005
set @index = charindex('|',@ysxx)
set @ret= LEFT(@ysxx,@index-1)
end
return @ret
END