Monday, October 12, 2020

Data Validation in SQL Server

DROP TABLE if exists #temp1,#temp2;


SELECT empno, HASHBYTES ('SHA2_256', CONCAT ([ename]

      ,[hiredate]

      ,[job]

      ,[deptno]

      ,CONVERT(DECIMAL(32,6),[sal])

      )) HashByte

      INTO #temp1

  FROM [prod].[scott].[EMP];


SELECT empno, HASHBYTES ('SHA2_256', CONCAT ([ename]

      ,[hiredate]

      ,[job]

      ,[deptno]

      ,CONVERT(DECIMAL(32,6),[sal])

      )) HashByte

      INTO #temp2

  FROM [stage].[scott].[EMP];



CREATE clustered INDEX IX ON #temp2  (empno);


CREATE clustered INDEX IX1 ON #temp1  (empno);


-- Data Validation


SELECT top 10  *  FROM #temp1 t1

  WHERE  not EXISTS (SELECT 1 FROM #temp2 t2 where t1.empno=t2.empno and t1.HashByte=t2.HashByte )


-- Sample Record


SELECT 'prod'

   [empno] 

      ,[ename]

      ,[hiredate]

      ,[job]

      ,[deptno]

      ,CONVERT(DECIMAL(32,6),[sal])

FROM [prod].[scott].[EMP]

WHERE [empno] = 7863

UNION ALL

SELECT 'stage'

   [empno] 

      ,[ename]

      ,[hiredate]

      ,[job]

      ,[deptno]

      ,CONVERT(DECIMAL(32,6),[sal])

FROM [stage].[scott].[EMP]

WHERE [empno] = 7863;

  

No comments:

Post a Comment

Delete Row Button to all records of Interactive Report in Oracle Apex

 1. add 'Delete' Del column to Report Query 2. Set the Following Properties for the DEL Column Type: Link Heading: Delete Targ...