You are on page 1of 4

List of changes Description

1 Removed NOT IN oprater and added not exists condition

Removed 6 unwanted distrinct's


1, table column with primary key we don’t want use distinct
2, if we used union we don’t want to use distinct
3, instaed of distinct we can use Group by
3 Temp table missing index creation
Query
"--- Before
DELETE FROM #QuoteIdTable
WHERE QuotationId NOT IN
(
SELECT QuotationId
FROM [Quotation].[quo].[QuotationDetail]
WHERE QuotationDetailId IN
(
SELECT QuotationDetailId FROM #QuoteDetailIdTable
)
);
----------------- After
DELETE tqt FROM #QuoteIdTable tqt --suren
where not exists (
select '*' from [Quotation].[quo].[QuotationDetail] qd
inner join #QuoteDetailIdTable tqd on (qd.QuotationDetailId = tqd.QuotationDetailId)
where tqt.QuotationId= qd.QuotationId
)

SELECT distinct
QuotationId,
[LastUpdatedOn],
[CreatedOn]
FROM [Quotation].[quo].Quotation q
------- After

SELECT
QuotationId,
[LastUpdatedOn],
[CreatedOn]
FROM [Quotation].[quo].Quotation q
------Before
SELECT distrinct
Q.CustomerId
FROM [Quotation].[quo].[Quotation] Q
INNER JOIN #QuoteDetailIdTable QDT
ON QDT.QuotationId = Q.QuotationId
UNION
SELECT distrinct
Q.CustomerId
FROM [Quotation].[quo].[Quotation] Q
INNER JOIN #RequoteCountTable RQ
ON RQ.QuotationId = Q.QuotationId
-----------After
SELECT
Q.CustomerId
FROM [Quotation].[quo].[Quotation] Q
INNER JOIN #QuoteDetailIdTable QDT
ON QDT.QuotationId = Q.QuotationId
UNION
SELECT
Q.CustomerId
FROM [Quotation].[quo].[Quotation] Q
INNER JOIN #RequoteCountTable RQ
ON RQ.QuotationId = Q.QuotationId
CREATE CLUSTERED INDEX ix_ReQuoteCountTable
ON #ReQuoteCountTable (QuotationId);
CREATE CLUSTERED INDEX ix_AgencyUserTable
ON #AgencyUserTable (AgencyUserId);

You might also like