select
A.SlNo
,A.[Company Code]
,A.[Document Number]
,A.[Document Type]
,CONVERT(varchar(10),A.[Document Date],101) AS [Document Date]
,A.[Reference]
,CAST(Null as nvarchar(5)) As NumericInvoice
,CONVERT(varchar(10),A.[Posting Date],101) AS [Posting Date]
,A.[Clearing Document]
,A.[Amount in doc# curr#]`enter code here`
,A.[Document currency]
,A.[Account]
,A.[Account Description]
,A.[User Name]
,A.dumptype
,CAST(Null As Varchar(5)) As Similarity
,CASE
When (A.[Reference] = B.[Reference] and A.[Amount in doc# curr#]= B.[Amount in doc# curr#]) then 'DUPEPAYA'
END As [Status]
,CAST(Null As Varchar(5)) As [DupeSets]
from MasterData A
Join InputData B on (A.[Reference] = B.[Reference] and A.[Amount in doc# curr#]= B.[Amount in doc# curr#])
Union All
select distinct
A.SlNo
,A.[Company Code]
,A.[Document Number]
,A.[Document Type]
,CONVERT(varchar(10),A.[Document Date],101) AS [Document Date]
,A.[Reference]
,CAST(Null as nvarchar(5)) As NumericInvoice
,CONVERT(varchar(10),A.[Posting Date],101) AS [Posting Date]
,A.[Clearing Document]
,A.[Amount in doc# curr#]
,A.[Document currency]
,A.[Account]
,A.[Account Description]
,A.[User Name]
,A.dumptype
,CAST(Null As Varchar(5)) As Similarity
,CASE
When (A.[Reference] = B.[Reference] and A.[Amount in doc# curr#]= B.[Amount in doc# curr#]) then 'DUPEPAYA'
END As [Status]
,DENSE_Rank () Over (order by A.[Reference], A.[Account Description], A.dumptype asc) As [DupeSets]
from InputData A
Join MasterData B on (A.[Reference] = B.[Reference] and A.[Amount in doc# curr#]= B.[Amount in doc# curr#])
order by A.[Reference], A.[Account Description], A.dumptype asc
Я хочу оптимизировать приведенный выше запрос, который приводит к дублированию от таблицы masterdata к таблице входных данных при небольшом количестве проверок, эти таблицы данных имеют дело с огромным объемом данных, поэтому для их выполнения требуется много времени.запрос.пожалуйста, помогите Примечание: я новичок в SQL.