0% found this document useful (0 votes)
112 views

Parameter Comparison Script - X3

This SQL query joins data from two databases (LIVE and PILOT01) on specific parameters and returns any rows that have differences in values or were updated after a given date. It allows filtering the results to only a specific parameter. Declared variables at the top control whether to return only rows with differences, the date to track changes from, and an optional parameter to filter on.

Uploaded by

ruzha
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)
112 views

Parameter Comparison Script - X3

This SQL query joins data from two databases (LIVE and PILOT01) on specific parameters and returns any rows that have differences in values or were updated after a given date. It allows filtering the results to only a specific parameter. Declared variables at the top control whether to return only rows with differences, the date to track changes from, and an optional parameter to filter on.

Uploaded by

ruzha
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/ 1

DECLARE @DIFFERENCES NVARCHAR(3)

DECLARE @PARAMETER NVARCHAR(20)


DECLARE @FROMDATE DATE

SET @DIFFERENCES = 'NO' ---- YES/NO TO TRACK DIFFERENCES


SET @FROMDATE = '2015-01-01' ---- TRACK CHANGES FROM SPECIFIED DATE
SET @PARAMETER = 'SPRIMOD' ---- TRACK A SPECIFIC PARAMETER OR LEAVE BLANK FOR ALL

SELECT * FROM
(
select 'FOLDER1' FOLDER, CHAPITRE_0 CHAPTER,VAL.PARAM_0 PARAMETER,GRPPAR_0
[GROUP] ,TEX.TEXTE_0 DESCRIPTION,CODACT_0 ACTIVITY_CODE,
VAL.CMP_0,VAL.FCY_0,VAL.VALEUR_0 VALUE , VAL.UPDDATTIM_0
from LIVE.ADOPAR PAR (nolock)
INNER JOIN LIVE.ATEXTE TEX on PAR.NAM_0=TEX.NUMERO_0 and TEX.LAN_0='ENG'
RIGHT JOIN LIVE.ADOVAL VAL ON PAR.PARAM_0=VAL.PARAM_0
) F1
FULL OUTER JOIN
(
select 'FOLDER2' FOLDER, CHAPITRE_0 CHAPTER,VAL.PARAM_0 PARAMETER,GRPPAR_0
[GROUP] ,TEX.TEXTE_0 DESCRIPTION,CODACT_0 ACTIVITY_CODE,
VAL.CMP_0,VAL.FCY_0,VAL.VALEUR_0 VALUE , VAL.UPDDATTIM_0
from PILOT01.ADOPAR PAR (nolock)
INNER JOIN PILOT01.ATEXTE TEX on PAR.NAM_0=TEX.NUMERO_0 and TEX.LAN_0='ENG'
RIGHT JOIN PILOT01.ADOVAL VAL ON PAR.PARAM_0=VAL.PARAM_0
) F2
ON F1.PARAMETER = F2.PARAMETER AND F1.CMP_0 = F2.CMP_0 AND F1.FCY_0 = F2.FCY_0
WHERE (( @DIFFERENCES = 'YES' AND ISNULL(F1.VALUE,'') <> ISNULL(F2.VALUE,'') )
OR (@DIFFERENCES = 'NO') )
AND ( F1.UPDDATTIM_0 >= @FROMDATE OR F2.UPDDATTIM_0 >= @FROMDATE )
AND ( (F1.PARAMETER = @PARAMETER OR RTRIM(@PARAMETER) IS NULL OR
RTRIM(@PARAMETER)='') OR (F2.PARAMETER = @PARAMETER OR RTRIM(@PARAMETER) IS NULL
OR RTRIM(@PARAMETER)=''))

You might also like