Created
January 2, 2018 16:18
-
-
Save codenamejason/19849e84f0d68d7bf96bc74be4c89e94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--SET ANSI_NULLS ON | |
--GO | |
--SET QUOTED_IDENTIFIER ON | |
--GO | |
--IF EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = | |
--OBJECT_ID(N'[dbo].[FormatSSN]') AND TYPE IN (N'FN', N'IF', N'TF', N'FS', N'FT')) | |
--DROP FUNCTION [dbo].[FormatSSN] | |
--GO | |
CREATE FUNCTION [dbo].[FormatSSN] (@UnformattedSSN varchar(50)) | |
RETURNS INT | |
AS | |
BEGIN | |
DECLARE @FormattedSSN varchar(12) = REPLACE(REPLACE(@UnformattedSSN,'-',''),' ','') | |
SET @FormattedSSN = CASE | |
WHEN ISNUMERIC(@FormattedSSN) !=1 THEN NULL | |
WHEN LEN(@FormattedSSN) <> 9 THEN NULL | |
ELSE @FormattedSSN | |
END | |
RETURN @FormattedSSN | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment