I have a query that requires ONE HUNDRED fields to be joined from one table to another. instead of manually going through the query designer, i decided to build the join using excel. When i put the code in to the SQL side of the query, then clicked designer, it choked on all 100 field comparisons and removed them. i proceeded to manually click drag the entire set of 100 field to join them all. somehow it worked. now when i look at the sql code for how access did it, it looks almost identical to my code. the only difference that i can identify is that instead of it going from A-Z, it goes Z-A.
Original Query
PARAMETERS pn TEXT (255)
,tt TEXT (255)
,sns Long
,sne Long
,ds DATETIME
,de DATETIME;
SELECT y.Short_Description1
,y.Data1
,y.Short_Description2
,y.Data2
,y.Short_Description3
,y.Data3
,y.Short_Description4
,y.Data4
,y.Short_Description5
,y.Data5
,y.Short_Description6
,y.Data6
,y.Short_Description7
,y.Data7
,y.Short_Description8
,y.Data8
,y.Short_Description9
,y.Data9
,y.Short_Description10
,y.Data10
,y.Short_Description11
,y.Data11
,y.Short_Description12
,y.Data12
,y.Short_Description13
,y.Data13
,y.Short_Description14
,y.Data14
,y.Short_Description15
,y.Data15
,y.Short_Description16
,y.Data16
,y.Short_Description17
,y.Data17
,y.Short_Description18
,y.Data18
,y.Short_Description19
,y.Data19
,y.Short_Description20
,y.Data20
,y.Short_Description21
,y.Data21
,y.Short_Description22
,y.Data22
,y.Short_Description23
,y.Data23
,y.Short_Description24
,y.Data24
,y.Short_Description25
,y.Data25
,y.Short_Description26
,y.Data26
,y.Short_Description27
,y.Data27
,y.Short_Description28
,y.Data28
,y.Short_Description29
,y.Data29
,y.Short_Description30
,y.Data30
,y.Short_Description31
,y.Data31
,y.Short_Description32
,y.Data32
,y.Short_Description33
,y.Data33
,y.Short_Description34
,y.Data34
,y.Short_Description35
,y.Data35
,y.Short_Description36
,y.Data36
,y.Short_Description37
,y.Data37
,y.Short_Description38
,y.Data38
,y.Short_Description39
,y.Data39
,y.Short_Description40
,y.Data40
,y.Short_Description41
,y.Data41
,y.Short_Description42
,y.Data42
,y.Short_Description43
,y.Data43
,y.Short_Description44
,y.Data44
,y.Short_Description45
,y.Data45
,y.Short_Description46
,y.Data46
,y.Short_Description47
,y.Data47
,y.Short_Description48
,y.Data48
,y.Short_Description49
,y.Data49
,y.Short_Description50
,y.Data50
,y.Short_Description51
,y.Data51
,y.Short_Description52
,y.Data52
,y.Short_Description53
,y.Data53
,y.Short_Description54
,y.Data54
,y.Short_Description55
,y.Data55
,y.Short_Description56
,y.Data56
,y.Short_Description57
,y.Data57
,y.Short_Description58
,y.Data58
,y.Short_Description59
,y.Data59
,y.Short_Description60
,y.Data60
,y.Short_Description61
,y.Data61
,y.Short_Description62
,y.Data62
,y.Short_Description63
,y.Data63
,y.Short_Description64
,y.Data64
,y.Short_Description65
,y.Data65
,y.Short_Description66
,y.Data66
,y.Short_Description67
,y.Data67
,y.Short_Description68
,y.Data68
,y.Short_Description69
,y.Data69
,y.Short_Description70
,y.Data70
,y.Short_Description71
,y.Data71
,y.Short_Description72
,y.Data72
,y.Short_Description73
,y.Data73
,y.Short_Description74
,y.Data74
,y.Short_Description75
,y.Data75
,y.Short_Description76
,y.Data76
,y.Short_Description77
,y.Data77
,y.Short_Description78
,y.Data78
,y.Short_Description79
,y.Data79
,y.Short_Description80
,y.Data80
,y.Short_Description81
,y.Data81
,y.Short_Description82
,y.Data82
,y.Short_Description83
,y.Data83
,y.Short_Description84
,y.Data84
,y.Short_Description85
,y.Data85
,y.Short_Description86
,y.Data86
,y.Short_Description87
,y.Data87
,y.Short_Description88
,y.Data88
,y.Short_Description89
,y.Data89
,y.Short_Description90
,y.Data90
,y.Short_Description91
,y.Data91
,y.Short_Description92
,y.Data92
,y.Short_Description93
,y.Data93
,y.Short_Description94
,y.Data94
,y.Short_Description95
,y.Data95
,y.Short_Description96
,y.Data96
,y.Short_Description97
,y.Data97
,y.Short_Description98
,y.Data98
,y.Short_Description99
,y.Data99
,y.Short_Description100
,y.Data100
,x.rownum
FROM qryIndividualTestData100Descriptions AS x
INNER JOIN IndividualTestData100 AS y ON (x.Short_Description1 =
y.Short_Description1)
AND (x.Short_Description2 = y.Short_Description2)
AND (x.Short_Description3 = y.Short_Description3)
AND (x.Short_Description4 = y.Short_Description4)
AND (x.Short_Description5 = y.Short_Description5)
AND (x.Short_Description6 = y.Short_Description6)
AND (x.Short_Description7 = y.Short_Description7)
AND (x.Short_Description8 = y.Short_Description8)
AND (x.Short_Description9 = y.Short_Description9)
AND (x.Short_Description10 = y.Short_Description10)
AND (x.Short_Description11 = y.Short_Description11)
AND (x.Short_Description12 = y.Short_Description12)
AND (x.Short_Description13 = y.Short_Description13)
AND (x.Short_Description14 = y.Short_Description14)
AND (x.Short_Description15 = y.Short_Description15)
AND (x.Short_Description16 = y.Short_Description16)
AND (x.Short_Description17 = y.Short_Description17)
AND (x.Short_Description18 = y.Short_Description18)
AND (x.Short_Description19 = y.Short_Description19)
AND (x.Short_Description20 = y.Short_Description20)
AND (x.Short_Description21 = y.Short_Description21)
AND (x.Short_Description22 = y.Short_Description22)
AND (x.Short_Description23 = y.Short_Description23)
AND (x.Short_Description24 = y.Short_Description24)
AND (x.Short_Description25 = y.Short_Description25)
AND (x.Short_Description26 = y.Short_Description26)
AND (x.Short_Description27 = y.Short_Description27)
AND (x.Short_Description28 = y.Short_Description28)
AND (x.Short_Description29 = y.Short_Description29)
AND (x.Short_Description30 = y.Short_Description30)
AND (x.Short_Description31 = y.Short_Description31)
AND (x.Short_Description32 = y.Short_Description32)
AND (x.Short_Description33 = y.Short_Description33)
AND (x.Short_Description34 = y.Short_Description34)
AND (x.Short_Description35 = y.Short_Description35)
AND (x.Short_Description36 = y.Short_Description36)
AND (x.Short_Description37 = y.Short_Description37)
AND (x.Short_Description38 = y.Short_Description38)
AND (x.Short_Description39 = y.Short_Description39)
AND (x.Short_Description40 = y.Short_Description40)
AND (x.Short_Description41 = y.Short_Description41)
AND (x.Short_Description42 = y.Short_Description42)
AND (x.Short_Description43 = y.Short_Description43)
AND (x.Short_Description44 = y.Short_Description44)
AND (x.Short_Description45 = y.Short_Description45)
AND (x.Short_Description46 = y.Short_Description46)
AND (x.Short_Description47 = y.Short_Description47)
AND (x.Short_Description48 = y.Short_Description48)
AND (x.Short_Description49 = y.Short_Description49)
AND (x.Short_Description50 = y.Short_Description50)
AND (x.Short_Description51 = y.Short_Description51)
AND (x.Short_Description52 = y.Short_Description52)
AND (x.Short_Description53 = y.Short_Description53)
AND (x.Short_Description54 = y.Short_Description54)
AND (x.Short_Description55 = y.Short_Description55)
AND (x.Short_Description56 = y.Short_Description56)
AND (x.Short_Description57 = y.Short_Description57)
AND (x.Short_Description58 = y.Short_Description58)
AND (x.Short_Description59 = y.Short_Description59)
AND (x.Short_Description60 = y.Short_Description60)
AND (x.Short_Description61 = y.Short_Description61)
AND (x.Short_Description62 = y.Short_Description62)
AND (x.Short_Description63 = y.Short_Description63)
AND (x.Short_Description64 = y.Short_Description64)
AND (x.Short_Description65 = y.Short_Description65)
AND (x.Short_Description66 = y.Short_Description66)
AND (x.Short_Description67 = y.Short_Description67)
AND (x.Short_Description68 = y.Short_Description68)
AND (x.Short_Description69 = y.Short_Description69)
AND (x.Short_Description70 = y.Short_Description70)
AND (x.Short_Description71 = y.Short_Description71)
AND (x.Short_Description72 = y.Short_Description72)
AND (x.Short_Description73 = y.Short_Description73)
AND (x.Short_Description74 = y.Short_Description74)
AND (x.Short_Description75 = y.Short_Description75)
AND (x.Short_Description76 = y.Short_Description76)
AND (x.Short_Description77 = y.Short_Description77)
AND (x.Short_Description78 = y.Short_Description78)
AND (x.Short_Description79 = y.Short_Description79)
AND (x.Short_Description80 = y.Short_Description80)
AND (x.Short_Description81 = y.Short_Description81)
AND (x.Short_Description82 = y.Short_Description82)
AND (x.Short_Description83 = y.Short_Description83)
AND (x.Short_Description84 = y.Short_Description84)
AND (x.Short_Description85 = y.Short_Description85)
AND (x.Short_Description86 = y.Short_Description86)
AND (x.Short_Description87 = y.Short_Description87)
AND (x.Short_Description88 = y.Short_Description88)
AND (x.Short_Description89 = y.Short_Description89)
AND (x.Short_Description90 = y.Short_Description90)
AND (x.Short_Description91 = y.Short_Description91)
AND (x.Short_Description92 = y.Short_Description92)
AND (x.Short_Description93 = y.Short_Description93)
AND (x.Short_Description94 = y.Short_Description94)
AND (x.Short_Description95 = y.Short_Description95)
AND (x.Short_Description96 = y.Short_Description96)
AND (x.Short_Description97 = y.Short_Description97)
AND (x.Short_Description98 = y.Short_Description98)
AND (x.Short_Description99 = y.Short_Description99)
AND (x.Short_Description100 = y.Short_Description100)
WHERE (
((y.[Part_Number]) LIKE [pn] & "*" & [tt])
AND (
(y.[Serial_Number]) >= [sns]
AND (y.[Serial_Number]) <= [sne]
)
AND (
(y.[Test_Date]) >= [ds]
AND (y.[Test_Date]) <= [de]
)
);
Access Generated version
PARAMETERS pn TEXT (255)
,tt TEXT (255)
,sns Long
,sne Long
,ds DATETIME
,de DATETIME;
SELECT y.Short_Description1
,y.Data1
,y.Short_Description2
,y.Data2
,y.Short_Description3
,y.Data3
,y.Short_Description4
,y.Data4
,y.Short_Description5
,y.Data5
,y.Short_Description6
,y.Data6
,y.Short_Description7
,y.Data7
,y.Short_Description8
,y.Data8
,y.Short_Description9
,y.Data9
,y.Short_Description10
,y.Data10
,y.Short_Description11
,y.Data11
,y.Short_Description12
,y.Data12
,y.Short_Description13
,y.Data13
,y.Short_Description14
,y.Data14
,y.Short_Description15
,y.Data15
,y.Short_Description16
,y.Data16
,y.Short_Description17
,y.Data17
,y.Short_Description18
,y.Data18
,y.Short_Description19
,y.Data19
,y.Short_Description20
,y.Data20
,y.Short_Description21
,y.Data21
,y.Short_Description22
,y.Data22
,y.Short_Description23
,y.Data23
,y.Short_Description24
,y.Data24
,y.Short_Description25
,y.Data25
,y.Short_Description26
,y.Data26
,y.Short_Description27
,y.Data27
,y.Short_Description28
,y.Data28
,y.Short_Description29
,y.Data29
,y.Short_Description30
,y.Data30
,y.Short_Description31
,y.Data31
,y.Short_Description32
,y.Data32
,y.Short_Description33
,y.Data33
,y.Short_Description34
,y.Data34
,y.Short_Description35
,y.Data35
,y.Short_Description36
,y.Data36
,y.Short_Description37
,y.Data37
,y.Short_Description38
,y.Data38
,y.Short_Description39
,y.Data39
,y.Short_Description40
,y.Data40
,y.Short_Description41
,y.Data41
,y.Short_Description42
,y.Data42
,y.Short_Description43
,y.Data43
,y.Short_Description44
,y.Data44
,y.Short_Description45
,y.Data45
,y.Short_Description46
,y.Data46
,y.Short_Description47
,y.Data47
,y.Short_Description48
,y.Data48
,y.Short_Description49
,y.Data49
,y.Short_Description50
,y.Data50
,y.Short_Description51
,y.Data51
,y.Short_Description52
,y.Data52
,y.Short_Description53
,y.Data53
,y.Short_Description54
,y.Data54
,y.Short_Description55
,y.Data55
,y.Short_Description56
,y.Data56
,y.Short_Description57
,y.Data57
,y.Short_Description58
,y.Data58
,y.Short_Description59
,y.Data59
,y.Short_Description60
,y.Data60
,y.Short_Description61
,y.Data61
,y.Short_Description62
,y.Data62
,y.Short_Description63
,y.Data63
,y.Short_Description64
,y.Data64
,y.Short_Description65
,y.Data65
,y.Short_Description66
,y.Data66
,y.Short_Description67
,y.Data67
,y.Short_Description68
,y.Data68
,y.Short_Description69
,y.Data69
,y.Short_Description70
,y.Data70
,y.Short_Description71
,y.Data71
,y.Short_Description72
,y.Data72
,y.Short_Description73
,y.Data73
,y.Short_Description74
,y.Data74
,y.Short_Description75
,y.Data75
,y.Short_Description76
,y.Data76
,y.Short_Description77
,y.Data77
,y.Short_Description78
,y.Data78
,y.Short_Description79
,y.Data79
,y.Short_Description80
,y.Data80
,y.Short_Description81
,y.Data81
,y.Short_Description82
,y.Data82
,y.Short_Description83
,y.Data83
,y.Short_Description84
,y.Data84
,y.Short_Description85
,y.Data85
,y.Short_Description86
,y.Data86
,y.Short_Description87
,y.Data87
,y.Short_Description88
,y.Data88
,y.Short_Description89
,y.Data89
,y.Short_Description90
,y.Data90
,y.Short_Description91
,y.Data91
,y.Short_Description92
,y.Data92
,y.Short_Description93
,y.Data93
,y.Short_Description94
,y.Data94
,y.Short_Description95
,y.Data95
,y.Short_Description96
,y.Data96
,y.Short_Description97
,y.Data97
,y.Short_Description98
,y.Data98
,y.Short_Description99
,y.Data99
,y.Short_Description100
,y.Data100
,x.rownum
FROM qryIndividualTestData100Descriptions AS x
INNER JOIN individualtestdata100 AS y ON (x.Short_Description100 =
y.Short_Description100)
AND (x.Short_Description99 = y.Short_Description99)
AND (x.Short_Description98 = y.Short_Description98)
AND (x.Short_Description97 = y.Short_Description97)
AND (x.Short_Description96 = y.Short_Description96)
AND (x.Short_Description95 = y.Short_Description95)
AND (x.Short_Description94 = y.Short_Description94)
AND (x.Short_Description93 = y.Short_Description93)
AND (x.Short_Description92 = y.Short_Description92)
AND (x.Short_Description91 = y.Short_Description91)
AND (x.Short_Description90 = y.Short_Description90)
AND (x.Short_Description89 = y.Short_Description89)
AND (x.Short_Description88 = y.Short_Description88)
AND (x.Short_Description87 = y.Short_Description87)
AND (x.Short_Description86 = y.Short_Description86)
AND (x.Short_Description85 = y.Short_Description85)
AND (x.Short_Description84 = y.Short_Description84)
AND (x.Short_Description83 = y.Short_Description83)
AND (x.Short_Description82 = y.Short_Description82)
AND (x.Short_Description81 = y.Short_Description81)
AND (x.Short_Description80 = y.Short_Description80)
AND (x.Short_Description79 = y.Short_Description79)
AND (x.Short_Description78 = y.Short_Description78)
AND (x.Short_Description77 = y.Short_Description77)
AND (x.Short_Description76 = y.Short_Description76)
AND (x.Short_Description75 = y.Short_Description75)
AND (x.Short_Description74 = y.Short_Description74)
AND (x.Short_Description73 = y.Short_Description73)
AND (x.Short_Description72 = y.Short_Description72)
AND (x.Short_Description71 = y.Short_Description71)
AND (x.Short_Description70 = y.Short_Description70)
AND (x.Short_Description69 = y.Short_Description69)
AND (x.Short_Description68 = y.Short_Description68)
AND (x.Short_Description67 = y.Short_Description67)
AND (x.Short_Description66 = y.Short_Description66)
AND (x.Short_Description65 = y.Short_Description65)
AND (x.Short_Description64 = y.Short_Description64)
AND (x.Short_Description63 = y.Short_Description63)
AND (x.Short_Description62 = y.Short_Description62)
AND (x.Short_Description61 = y.Short_Description61)
AND (x.Short_Description60 = y.Short_Description60)
AND (x.Short_Description59 = y.Short_Description59)
AND (x.Short_Description58 = y.Short_Description58)
AND (x.Short_Description57 = y.Short_Description57)
AND (x.Short_Description56 = y.Short_Description56)
AND (x.Short_Description55 = y.Short_Description55)
AND (x.Short_Description54 = y.Short_Description54)
AND (x.Short_Description53 = y.Short_Description53)
AND (x.Short_Description52 = y.Short_Description52)
AND (x.Short_Description51 = y.Short_Description51)
AND (x.Short_Description50 = y.Short_Description50)
AND (x.Short_Description49 = y.Short_Description49)
AND (x.Short_Description48 = y.Short_Description48)
AND (x.Short_Description47 = y.Short_Description47)
AND (x.Short_Description46 = y.Short_Description46)
AND (x.Short_Description45 = y.Short_Description45)
AND (x.Short_Description44 = y.Short_Description44)
AND (x.Short_Description43 = y.Short_Description43)
AND (x.Short_Description42 = y.Short_Description42)
AND (x.Short_Description41 = y.Short_Description41)
AND (x.Short_Description40 = y.Short_Description40)
AND (x.Short_Description39 = y.Short_Description39)
AND (x.Short_Description38 = y.Short_Description38)
AND (x.Short_Description37 = y.Short_Description37)
AND (x.Short_Description36 = y.Short_Description36)
AND (x.Short_Description35 = y.Short_Description35)
AND (x.Short_Description34 = y.Short_Description34)
AND (x.Short_Description33 = y.Short_Description33)
AND (x.Short_Description32 = y.Short_Description32)
AND (x.Short_Description31 = y.Short_Description31)
AND (x.Short_Description30 = y.Short_Description30)
AND (x.Short_Description29 = y.Short_Description29)
AND (x.Short_Description28 = y.Short_Description28)
AND (x.Short_Description27 = y.Short_Description27)
AND (x.Short_Description26 = y.Short_Description26)
AND (x.Short_Description25 = y.Short_Description25)
AND (x.Short_Description24 = y.Short_Description24)
AND (x.Short_Description23 = y.Short_Description23)
AND (x.Short_Description22 = y.Short_Description22)
AND (x.Short_Description21 = y.Short_Description21)
AND (x.Short_Description20 = y.Short_Description20)
AND (x.Short_Description19 = y.Short_Description19)
AND (x.Short_Description18 = y.Short_Description18)
AND (x.Short_Description17 = y.Short_Description17)
AND (x.Short_Description16 = y.Short_Description16)
AND (x.Short_Description15 = y.Short_Description15)
AND (x.Short_Description14 = y.Short_Description14)
AND (x.Short_Description13 = y.Short_Description13)
AND (x.Short_Description12 = y.Short_Description12)
AND (x.Short_Description11 = y.Short_Description11)
AND (x.Short_Description10 = y.Short_Description10)
AND (x.Short_Description9 = y.Short_Description9)
AND (x.Short_Description8 = y.Short_Description8)
AND (x.Short_Description7 = y.Short_Description7)
AND (x.Short_Description6 = y.Short_Description6)
AND (x.Short_Description5 = y.Short_Description5)
AND (x.Short_Description4 = y.Short_Description4)
AND (x.Short_Description3 = y.Short_Description3)
AND (x.Short_Description2 = y.Short_Description2)
AND (x.Short_Description1 = y.Short_Description1)
WHERE (
((y.Part_Number) LIKE [pn] & "*" & [tt])
AND (
(y.Serial_Number) >= [sns]
AND (y.Serial_Number) <= [sne]
)
AND (
(y.Test_Date) >= [ds]
AND (y.Test_Date) <= [de]
)
);
Why does access choke on the query?
I have two tables. One is todays prices and one is yesterdays prices. There is a job which updates each table over night. Yesterdays prices is a copy of todays before it gets updated.
I am trying to create a table which shows the differences between the tables.
To do this I am using a full outer join. I am filtering down my criteria to make it faster as both tables are over 48 million rows.
My current code is like this.
WITH differ AS
(
SELECT
tAP.CustomerID, tAP.ProductID, yAP.CustomerID AS 'Yest_CustomerID', yAP.ProductID AS 'Yest_ProductID',
tAP.PDG, tAP.DiscPct1, tAP.DiscPct2,
yAP.DiscPct1 AS 'Yest_DiscPct1',
yAP.DiscPct2 AS 'Yest_DiscPct2',
CONVERT(DECIMAL(18,2),tAP.DiscPct1 - yAP.DiscPct1) AS 'DiscPct1_Difference',
CONVERT(DECIMAL(18,2),tAP.DiscPct2 - yAP.DiscPct2) AS 'DiscPct2_Difference',
tAP.internalSPANumber, yAP.internalSPANumber AS 'Yest_InternalSPANumber', tAP.SPAUniqueReference,
tAP.Project,
tAP.ExpiryDate,tAP.Subaddress, tAP.PriceType, yAP.PriceType AS 'Yest_PriceType', tAP.ListPrice,
tAP.NettPrice, yAP.NettPrice AS 'Yest_NettPrice',
CONVERT(DECIMAL(18,2),tAP.NettPrice- yAP.NettPrice) AS 'NettPrice_Difference'
FROM tbl_Prices tAP FULL OUTER JOIN tbl_Prices_Yesterday yAP ON tAP.CustomerId = yAP.CustomerID AND tAP.ProductID = yAP.ProductID
AND tAP.PDG = yAP.PDG AND tAP.Project = yAP.Project AND tAP.PriceType = yAP.PriceType
WHERE (((tAP.DiscPct1 <> yAP.DiscPct1)
OR (tAP.DiscPct2 <> yAP.DiscPct2)
OR (yAP.CustomerID IS NULL)
OR (tAP.CustomerID IS NULL)
OR (tAP.NettPrice <> yAP.NettPrice)
OR (tAP.InternalSPANumber <> yAP.InternalSPANumber))
AND
(
tAP.ProductID = '10238610' OR tAP.ProductID = '10238620'
OR tAP.ProductID = '10238621' OR tAP.ProductID = '10238687'
OR tAP.ProductID = '10238688' OR yAP.ProductID = '10238610'
OR yAP.ProductID = '10238620' OR yAP.ProductID = '10238621'
OR yAP.ProductID = '10238687' OR yAP.ProductID = '10238688')
)
)
SELECT * INTO tbl_Difference FROM differ
Anyway to make this faster?
Can you filter the 2 large tables before you try to join them using AND filter in your where?
WITH tAPcte AS
(
SELECT * -- fields you need
FROM tbl_Prices
WHERE ProductID IN ('10238610',
'10238620',
'10238621',
'10238687',
'10238688')
),
yAPcte AS
(
SELECT * -- fields you need
FROM tbl_Prices_Yesterday
WHERE ProductID IN ('10238610',
'10238620',
'10238621',
'10238687',
'10238688')
)
differ AS
(
SELECT
tAP.CustomerID, tAP.ProductID, yAP.CustomerID AS 'Yest_CustomerID', yAP.ProductID AS 'Yest_ProductID',
tAP.PDG, tAP.DiscPct1, tAP.DiscPct2,
yAP.DiscPct1 AS 'Yest_DiscPct1',
yAP.DiscPct2 AS 'Yest_DiscPct2',
CONVERT(DECIMAL(18,2),tAP.DiscPct1 - yAP.DiscPct1) AS 'DiscPct1_Difference',
CONVERT(DECIMAL(18,2),tAP.DiscPct2 - yAP.DiscPct2) AS 'DiscPct2_Difference',
tAP.internalSPANumber, yAP.internalSPANumber AS 'Yest_InternalSPANumber', tAP.SPAUniqueReference,
tAP.Project,
tAP.ExpiryDate,tAP.Subaddress, tAP.PriceType, yAP.PriceType AS 'Yest_PriceType', tAP.ListPrice,
tAP.NettPrice, yAP.NettPrice AS 'Yest_NettPrice',
CONVERT(DECIMAL(18,2),tAP.NettPrice- yAP.NettPrice) AS 'NettPrice_Difference'
FROM tAPcte tAP FULL OUTER JOIN yAPcte yAP ON tAP.CustomerId = yAP.CustomerID AND tAP.ProductID = yAP.ProductID
AND tAP.PDG = yAP.PDG AND tAP.Project = yAP.Project AND tAP.PriceType = yAP.PriceType
WHERE (((tAP.DiscPct1 <> yAP.DiscPct1)
OR (tAP.DiscPct2 <> yAP.DiscPct2)
OR (yAP.CustomerID IS NULL)
OR (tAP.CustomerID IS NULL)
OR (tAP.NettPrice <> yAP.NettPrice)
OR (tAP.InternalSPANumber <> yAP.InternalSPANumber))
)
SELECT * INTO tbl_Difference FROM differ