日期:2014-05-17 浏览次数:20717 次
--将15位身份证升级成18位的用户定义函数
CREATE FUNCTION ID15TO18 (@id15 char(15))
RETURNS CHAR(18) AS
BEGIN
DECLARE @ID18 CHAR(18)
DECLARE @S1 AS INTEGER
DECLARE @S2 AS INTEGER
DECLARE @S3 AS INTEGER
DECLARE @S4 AS INTEGER
DECLARE @S5 AS INTEGER
DECLARE @S6 AS INTEGER
DECLARE @S7 AS INTEGER
DECLARE @S8 AS INTEGER
DECLARE @S9 AS INTEGER
DECLARE @S10 AS INTEGER
DECLARE @S11 AS INTEGER
DECLARE @S12 AS INTEGER
DECLARE @S13 AS INTEGER
DECLARE @S14 AS INTEGER
DECLARE @S15 AS INTEGER
DECLARE @S16 AS INTEGER
DECLARE @S17 AS INTEGER
DECLARE @S18 AS INTEGER
SET @S1 = SUBSTRING(@ID15,1,1)
SET @S2 = SUBSTRING(@ID15,2,1)
SET @S3 = SUBSTRING(@ID15,3,1)
SET @S4 = SUBSTRING(@ID15,4,1)
SET @S5 = SUBSTRING(@ID15,5,1)
SET @S6 = SUBSTRING(@ID15,6,1)
SET @S7 = 1
SET @S8 = 9
SET @S9 = SUBSTRING(@ID15,7,1)
SET @S10 = SUBSTRING(@ID15,8,1)
SET @S11 = SUBSTRING(@ID15,9,1)
SET @S12 = SUBSTRING(@ID15,10,1)
SET @S13 = SUBSTRING(@ID15,11,1)
SET @S14 = SUBSTRING(@ID15,12,1)
SET @S15 = SUBSTRING(@ID15,13,1)
SET @S16 = SUBSTRING(@ID15,14,1)
SET @S17 = SUBSTRING(@ID15,15,1)
SET @S18 = ( (@S1*7) + (@S2*9) + (@S3*10) + (@S4*5) + (@S5*8) +
(@S6*4) + (@S7*2) + (@S8*1) + (@S9*6) + (@S10*3) +
(@S11*7) + (@S12*9) + (@S13*10) + (@S14*5) + (@S15*8) +
(@S16*4) + (@S17*2) ) % 11
SET @ID18 = SUBSTRING(@ID15,1,6) + '19' + SUBSTRING(@ID15,7,9) +
&nb