SQL°æ±¾Éí·ÝÖ¤¸ñʽÑéÖ¤ 0Ϊ´íÎó£¬1ΪÕýÈ·
CREATE function [dbo].[IsID](@str nvarchar(18),@sex int)--´«ÈëÁ½¸ö±äÁ¿ Éí·ÝÖ¤ºÍÐÔ±ð(ÄÐ1Å®2)
returns bit
as
begin
declare @len int
declare @result bit
--set @result=0
set @len=len(@str)
if(@len!=18 and @len!=15)--³¤¶ÈÊÇ18λ»ò15λ
begin
set @result=0
end
else
if(case when @len=18 then left(@str,17) else @str end like '%[^0-9]%' )--15λÉí·Ý֤ҪΪÊý×Ö,18λÉí·Ý֤ǰ17λ±ØÐëÊÇÊý×Ö
begin
set @result=0
end
else
if(@len=18)--Èç¹ûÉí·ÝÖ¤ÊÇ18λ
begin--½øÐÐÂß¼¼ÆËã
declare @k int
declare @l nvarchar(11)
set @l='10X98765432'
set @k=
convert(int,left(@str,1))*7+
convert(int,substring(@str,2,1))*9+
convert(int,substring(@str,3,1))*10+
convert(int,substring(@str,4,1))*5+
convert(int,substring(@str,5,1))*8+
convert(int,substring(@str,6,1))*4+
convert(int,substring(@str,7,1))*2+
convert(int,substring(@str,8,1))*1+
convert(int,substring(@str,9,1))*6+
convert(int,substring(@str,10,1))*3+
convert(int,substring(@str,11,1))*7+
convert(int,substring(@str,12,1))*9+
convert(int,substring(@str,13,1))*10+
convert(int,substring(@str,14,1))*5+
convert(int,substring(@str,15,1))*8+
convert(int,substring(@str,16,1))*4+
convert(int,substring(@str,17,1))*2
set @k=@k%11
if(Upper(right(@str,1))!=substring(@l,@k+1,1))--Âß¼¼ÆËãµÄ½á¹ûºÍÉí·ÝÖ¤×îºóһλ±ØÐëÏàµÈ
begin
set @result=0
end
else
if(convert(int,substring(@str,17,1))%2!=@sex%2 and @sex in (1,2))--17λ´ú±íÐÔ±ð,ÆæÊýÊÇÄÐÐÔ,żÊýΪŮÐÔ
begin
set @result=0
end
else
&nbs
×î½ü,Òò¸öÈ˵çÄÔÓ²ÅÌËð»µ,йºÈëÁË500GµÄ´óÓ²ÅÌ,°²×°ÁËwindows7,ÔÚwin7ÉÏ°²×°Á˶à¸öÐéÄâxp»ú,ÐéÄâ»úÓëʵ¼ÊµÄ»úÆ÷(Ö÷»ú)×é³ÉÁËÒ»¸ö¾ÖÓòÍø,ʵÏÖÔÚÐéÄâ»úÖÐͨ¹ýÔ¶³ÌÁ¬½ÓÖ÷»úµÄsql server.ÏÖ½«ÎÒµÄÊÔÑé¹ý³Ì½éÉÜÈçÏÂ,¹©ÓÐÐËȤ³¢ÊԵĴóÏÀ²Î¿¼.
1. °²×°ÐéÄâ»ú»·¾³.
ÏÈ°²×°window7.0Æì½¢°æ (רҵÓëÆóÒµ°æÒ²¿ ......