0% found this document useful (0 votes)
12 views3 pages

Queries 2

The document provides SQL queries for validating marketing activity and data in ODS tables, including checking for data types, upper case values, null values, date and time formats, numeric values, duplicate records, and encryption/decryption errors. It includes over 30 validation queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Queries 2

The document provides SQL queries for validating marketing activity and data in ODS tables, including checking for data types, upper case values, null values, date and time formats, numeric values, duplicate records, and encryption/decryption errors. It includes over 30 validation queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Queries for Marketing Activity and ODS

Enrollment Validation rules:


-----------------------------------------------------------------------------------
---------------------------------------------------------
1. This would be generic query to give columns, data type and max length for field.
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'your_table_name';

2.Validate all the data in column to be in upper case.


SELECT * FROM Table WHERE UPPER (ColumnName) != ColumnName COLLATE
Latin1_General_CS_AS

3.Validate if data is leading with 0


SELECT FORMAT (EmployeeID, '000000') FROM dbo.RequestItems WHERE ID=0

4.Record count in the Table


SELECT count(*) FROM 'your_table_name';

5.Description of a Table
DESC 'your_table_name';

6. To identify which record has been skipped after processing


SELECT ColumnName FROM 'your_table_name' WHERE String=String;

EDIT Rules:
7. matching records of column of one table to column of other table
Eg: Validate that the ID exists in DWH.L_SOURCE
SELECT SOURCE_ID FROM SchemaName.'your_table_name1' WHERE EXISTS (SELECT SOURCE_ID
FROM SchemaName.'your_table_name2');

8. Check for null values


SELECT ColumnName FROM 'your_table_name' Where ColumnName is null;

9. Check for Valid date format


SELECT MerchandiseName, Cost, FORMAT (Now (),'YYYY-MM-DD') AS PerDate FROM
Merchandise; ---- TBC // change the date for accordingly

10. Check for time format


hh:mm:ss
SELECT *FROM yourTableName
WHERE yourColumnName REGEXP '^[0-2][0-3]:[0-5][0-9]:[0-5][0-9]$';

11. Cannot have any numeric (0-9) in the string if provided.


SELECT *FROM yourTableName
WHERE yourColumnName REGEXP '^[0-9]$';
OR
SELECT your_column
FROM your_table
WHERE your_column ~ '[0-9]';

12. Must have at least two alpha characters.


SELECT *
FROM your_table
WHERE LENGTH(REGEXP_REPLACE(your_column, '[^a-zA-Z]', '')) >= 2;
13. If Address is provided, Address Line 1 is required as part of combined address
fields. The address should include a minimum of Address Line 1 + City + State +
Zip5
SELECT Address Line 1, City, State, Zip5 FROM 'your_table_name' if Address Line 1
is

14.Check for null values


SELECT ColumnName FROM 'your_table_name' Where ColumnName is not null;

15. check for values which are in other table


SELECT ColumnName FROM yourTableName WHERE EXISTS (SELECT ColumnName FROM
AnotherTable);

16. Validation for numeric values


SELECT ColumnName FROM yourTableName where ColumnName between '00001' and '99950';

17. ColumnName contains 'Y', 'N' or Spaces


SELECT ColumnName FROM yourTableName WHERE ColumnName in ('Y','N') or LIKE '% %';
OR
SELECT ColumnName FROM yourTableName WHERE ColumnName in ('Y','N',' ','y','n');
// can be altered for any other flags eg:(I, O)

18. Verify if the field ColumnName contains exact 10 digit number values
select ColumnName from TABLE_NAME where regexp_like(phone_number,'^[[:digit:]]
{10}$') ;
OR
select ColumnName from TABLE_NAME where REGEXP '^[0-9]{10}$';

Verify for special characters:


SELECT LastName FROM `DB`.`PLANNAME` WHERE NOT LastName REGEXP '[A-Za-z0-9]';
OR
select * from MyTable where MyFieldName like ‘%[!”%#$&”()*+,-./:;<=>?@]%’

19. Verify if the field ColumnName contains 1st digit of number as "0" or "1"
select ColumnName from TABLE_NAME where column_name LIKE '0%' OR column_name LIKE
'1%'

20. Verify if the field column_name contains last 7 digits numbers all zeroes
SELECT ColumnName FROM yourTableName WHERE ColumnName LIKE '___0000000';

21. Verify if the field column_name contains all 10 digit numbers same
select ColumnName from TABLE_NAME where REGEXP '^(\d)\1*$'; // change the
number "^(\d)\1*$" in this to verify for required digit

22. Verify if the field Email Address contains atleast one non-blank character
before '@' Character
SELECT ColumnName FROM yourTableName WHERE ColumnName LIKE '% @%';

23. Validation for email address


SELECT ColumnName FROM yourTableName WHERE ColumnName PATINDEX('%[^a-z,0-9,@,.,_]
%', REPLACE(email, '-', 'a')) = 0;

24. The field shouldn't have valid date piror to "1900/01/01", if it is a piror
date then set field to null
SELECT column_name from yourTableName where date to char 19000101';

25. Verify if the field DOB contains valid date when compared to "SESSSTARTTIME"
SELECT *
FROM table_name
WHERE date_A >= date_B;

26. to check for duplicate records:


SELECT column_name1,column_name2,COUNT(*)
FROM table_name
GROUP BY column_name1,column_name2
HAVING COUNT(*)>1;

27.For combination duplicates(number of times repeated):


select contact_point_id,contact_point_value, CONTACT_POINT_TYPE_CODE,count(*)
from VIOC_FUSION.W_SRC_PROFILE_EMAIL
group by contact_point_id,contact_point_value, CONTACT_POINT_TYPE_CODE
having count(*)>1
order by count(*);

28.Verify if the field Inbound Outbound Ind contains 'I' or 'O'


select column_name from table_name where column_name like '%I%' or column_name like
'%O%';

29. Verify if the field contains decimal number


select ColumnName from TABLE_NAME where REGEXP '^[1-9]\d*(\.\d+)?$';

30. Verify the convert rule Uppercase // it will return 0 records


Select column_name from dwh.table_name
minus
Select upper(column_name) from stage.table_name;

31. Verify the convert rule Trimmed // if all the records converted it will return
0 records
Select column_name from dwh.table_name
minus
Select trim(column_name) from stage.table_name;

32. In a single record one colum data is populated other column data is not
populated
Select column_name1, column_name2 from table_name where column_name1 is not null
and column_name2 is null;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Query to check for En/Dy error in process monitor :

select * from process_monitor


where job_name = 'Encrypt-Decrypt-Files' and file_name = 'TealiumSessions_20230401-
lz-to-stage.txt.pgp'
order by last_updated desc;

use above query to check the status of enc or dec file


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Query to check for En/Dy error in process monitor :

select * from HUMA_OPS.feed_configuration;


select * from HUMA_OPS.file_tracker where feed_id = 34;
select * from HUMA_OPS.process_monitor where file_name = 'ORIGIN_validdata.csv.pgp'
order by last_updated desc ;
select * from HUMA_OPS.status_monitor;

You might also like