createFUNCTION[fn_ValidateIDC] ( @idcvarchar(18) )RETURNSBIT AS begin if (isnumeric(@idc)=1andlen(@idc)=15andisdate(substring(@idc ,7,6))=1 and (right(@idc ,1)='0'orright(@idc ,1)='1')) or (len(@idc )=18andisnumeric(left(@idc ,17))=1andisdate(substring(@idc ,7,8))=1 andpatindex('%[X0-9]%',right(@idc ,1))>0) return1 return0 end go select dbo.fn_ValidateIDC('12345619780901231X') dropfunction fn_ValidateIDC