Last active
October 13, 2015 17:32
-
-
Save clintmjohnson/76b9cf046d2584f488bd to your computer and use it in GitHub Desktop.
This CASE Statement checks to see if a string is a Valid UPC Number or Not. - It verifies that the string has only Numbers, and its length is 12
This file contains 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
USE DatabaseNameHere | |
SELECT | |
-- This CASE Expression Verifies that the Value in the UPC Field is All Numbers and It's Total Length is 12 | |
,CASE WHEN ISNUMERIC(UPC) = 1 AND LEN([UPC]) = 12 THEN [UPC] | |
WHEN ISNUMERIC(UPC) = 1 AND LEN([UPC]) = 11 THEN '0'+[UPC] | |
ELSE '' END AS [UPC] | |
FROM dbo.YourTableNameHere |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment