Last active
August 30, 2025 06:54
-
-
Save aolufisayo/7b4b929853ec12a484a36255acada6a2 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
| SELECT | |
| [CustomerID], | |
| [Forenames] AS [Firstname], | |
| [Surname], | |
| [DOB], | |
| -- Rule violations | |
| CASE | |
| WHEN [Forenames] IS NULL OR LEN([Forenames]) < 2 OR [Forenames] LIKE '%[^A-Za-z]%' | |
| THEN 'FirstName not in expected format - Text' | |
| ELSE NULL | |
| END AS Rule_FirstName, | |
| CASE | |
| WHEN [Surname] IS NULL OR LEN([Surname]) < 2 OR [Surname] LIKE '%[^A-Za-z]%' | |
| THEN 'Surname not in expected format - Text' | |
| ELSE NULL | |
| END AS Rule_Surname, | |
| CASE | |
| WHEN [DOB] IS NULL THEN 'DoB not valid' | |
| WHEN [DOB] = '1900-01-01' THEN 'DoB is not accurate' | |
| ELSE NULL | |
| END AS Rule_dob, | |
| -- Count failed rules | |
| ( | |
| CASE WHEN [Forenames] IS NULL OR LEN([Forenames]) < 2 OR [Forenames] LIKE '%[^A-Za-z]%' THEN 1 ELSE 0 END + | |
| CASE WHEN [Surname] IS NULL OR LEN([Surname]) < 2 OR [Surname] LIKE '%[^A-Za-z]%' THEN 1 ELSE 0 END + | |
| CASE WHEN [DOB] IS NULL OR [DOB] = '1900-01-01' THEN 1 ELSE 0 END | |
| ) AS FailedRulesCount, | |
| -- Data quality label | |
| CASE | |
| WHEN | |
| (CASE WHEN [Forenames] IS NULL OR LEN([Forenames]) < 2 OR [Forenames] LIKE '%[^A-Za-z]%' THEN 1 ELSE 0 END + | |
| CASE WHEN [Surname] IS NULL OR LEN([Surname]) < 2 OR [Surname] LIKE '%[^A-Za-z]%' THEN 1 ELSE 0 END + | |
| CASE WHEN [DOB] IS NULL OR [DOB] = '1900-01-01' THEN 1 ELSE 0 END) = 0 | |
| THEN 'Valid' | |
| ELSE 'Invalid' | |
| END AS Quality | |
| FROM [dbo].[Customer] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment