2014-06-12 2 views
0

현재 실행하는 데 4 분이 걸리는 저장 프로 시저가 있습니다. 나는 약 2 분 정도 내려 가고있다. 쿼리는 기본적으로 약 25,000 행의 테이블을 조사합니다. 각 항목을 잡고 약 230 행의 표와 일치하는 항목을 찾습니다.SQL 쿼리를 여러 조인으로 더 잘 수행하기

SET NOCOUNT ON; 

DECLARE @Iterator INT 
DECLARE @RowCount INT 
DECLARE @tempView TABLE (viewID int identity, 
         intCarrierCode int, 
         chrDlrNum varchar(50), 
         chrPgmCode varchar(5), 
         chrCvgCode varchar(5), 
         chrTransType varchar(5), 
         chrFeeType varchar(5), 
         chrPayeeType varchar(5), 
         intPayeeCode int, 
         Count int, 
         Amount smallmoney); 
DECLARE @tempTable TABLE (tableID int identity, 
         inbAcctgID int, 
         chrCarrierDesc varchar(50), 
         chrCarrierDescSht varchar(50), 
         intAcctCustID int, 
         intAcctCo int, 
         intAcctCoRec int, 
         chrPgmCode varchar(5), 
         intCarrierCode int, 
         chrDlrNum varchar(50), 
         chrCvgCode varchar(5), 
         chrPayeeType varchar(5), 
         chrFeeType varchar(5), 
         intPayeeCode int, 
         chrTransType varchar(5), 
         Count int, 
         Amount smallmoney) 

Truncate Table tblPayeeTransactionsMatchMonthEnd 

INSERT into @tempView  (intCarrierCode,chrDlrNum,chrPgmCode,chrCvgCode,chrTransType,chrFeeType,chrPayeeType,intPay eeCode,Count,Amount) 
SELECT * FROM dbo.viewMonthendArchiveGroupByCovg Where chrPgmCode <> 'BIW' and chrPayeeType <> 'M' and chrTransType Not in ('CXS','VOD','SUS','DEN') and Amount <> 0 


SET @Iterator = 1 
SET @RowCount = (SELECT COUNT(*) FROM @tempView) 

WHILE (@Iterator <= @RowCount) 
BEGIN 

IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
     and A.chrPayeeType = V.chrPayeeType 
     and A.chrFeeType = V.chrFeeType 
     and (A.intPayeeCode = V.intPayeeCode OR A.intPayeeCode is NULL) 
     and (A.chrCvgCode = V.chrCvgCode OR A.chrCvgCode is NULL) 
     and (A.chrDlrNum = V.chrDlrNum OR A.chrDlrNum is NULL) 
     and (A.chrTransType = V.chrTransType OR A.chrTransType IS NULL) 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
      and A.chrPayeeType = V.chrPayeeType 
      and A.chrFeeType = V.chrFeeType 
      and (A.intPayeeCode = V.intPayeeCode OR A.intPayeeCode is NULL) 
      and (A.chrCvgCode = V.chrCvgCode OR A.chrCvgCode is NULL) 
      and (A.chrDlrNum = V.chrDlrNum OR A.chrDlrNum is NULL) 
      and (A.chrTransType = V.chrTransType OR A.chrTransType IS NULL) 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
     and A.chrPayeeType = V.chrPayeeType 
     and A.chrFeeType = V.chrFeeType 
     and (A.intPayeeCode = V.intPayeeCode OR A.intPayeeCode is NULL) 
     and (A.chrCvgCode = V.chrCvgCode OR A.chrCvgCode is NULL) 
     and (A.chrDlrNum = V.chrDlrNum OR A.chrDlrNum is NULL) 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
      and A.chrPayeeType = V.chrPayeeType 
      and A.chrFeeType = V.chrFeeType 
      and (A.intPayeeCode = V.intPayeeCode OR A.intPayeeCode is NULL) 
      and (A.chrCvgCode = V.chrCvgCode OR A.chrCvgCode is NULL) 
      and (A.chrDlrNum = V.chrDlrNum OR A.chrDlrNum is NULL) 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
     and A.chrPayeeType = V.chrPayeeType 
     and A.chrFeeType = V.chrFeeType 
     and (A.intPayeeCode = V.intPayeeCode OR A.intPayeeCode is NULL) 
     and (A.chrCvgCode = V.chrCvgCode OR A.chrCvgCode is NULL) 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
      and A.chrPayeeType = V.chrPayeeType 
      and A.chrFeeType = V.chrFeeType 
      and (A.intPayeeCode = V.intPayeeCode OR A.intPayeeCode is NULL) 
      and (A.chrCvgCode = V.chrCvgCode OR A.chrCvgCode is NULL) 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
     and A.chrPayeeType = V.chrPayeeType 
     and A.chrFeeType = V.chrFeeType 
     and A.intPayeeCode = V.intPayeeCode 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
      and A.chrPayeeType = V.chrPayeeType 
      and A.chrFeeType = V.chrFeeType 
      and (A.intPayeeCode = V.intPayeeCode) 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
     and A.chrPayeeType = V.chrPayeeType 
     and A.chrFeeType = V.chrFeeType 
     and A.intPayeeCode is NULL 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
      and A.chrPayeeType = V.chrPayeeType 
      and A.chrFeeType = V.chrFeeType 
      and A.intPayeeCode is NULL 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
     and A.chrPayeeType = V.chrPayeeType 
     and A.chrFeeType = V.chrFeeType 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
      and A.chrPayeeType = V.chrPayeeType 
      and A.chrFeeType = V.chrFeeType 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
     and A.chrPayeeType = V.chrPayeeType 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
      and A.chrPayeeType = V.chrPayeeType 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
     and A.intCarrierCode = V.intCarrierCode 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
      and A.intCarrierCode = V.intCarrierCode 
     where V.viewID = @Iterator) 
END 
ELSE IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
     where V.viewID = @Iterator) 
END 
ELSE 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (SELECT NULL,NULL,NULL,NULL,NULL,NULL,V.chrPgmCode,V.intCarrierCode, V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     FROM @tempView as V 
     where V.viewID = @Iterator) 
END 

Set @Iterator = @Iterator + 1 
END 

Begin 

Insert into tblPayeeTransactionsMatchMonthEnd(inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
Select inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount from @tempTable 

End` 

죄송합니다. 어떤 도움이라도 대단히 감사 할 것입니다. Select Count (*)에서 하나의 열만 계산하려고 시도했지만 0 차이를 만들었습니다.

+0

모든 조건, 그 다음에는 'ELSE'이외의 다른 데이터는 정확히 같은 데이터를 삽입합니다. 'A.inbAcctgID, A.chrCarrierDesc, A.chrCarrierDesc, A.chrCarrierDescSht, A.intAcctCustID, A.intAcctCo를 선택하십시오. , A.intAcctCoRec, A.chrPgmCode, A.intCarrierCode, V.chrDlrNum, V.chrCvgCode, V.chrPayeeType, V.chrFeeType, V.intPayeeCode, V.chrTransType, V.Count, V.Amount' into @tempTable ' 뭔가 빠졌어? – Serpiton

+1

이것은 쿼리가 아니며 집합 기반 환경에서 절차 적 코드입니다. 마찬가지로 : SLOW. 그것을 기반으로 설정하고 행복하게. 실행 계획을 확인하고 필요한 모든 관련 지표를 추가하십시오. 끝마친. 임시 테이블이 필요 없습니다. – TomTom

+0

"make it set based"란 무엇을 의미합니까? – Zingo

답변

1

정확하게 무엇이 잘못 되었는가하는 것이 정말로 어렵지만, 먼저 where 절에서 사용하고 내 동조에서 ON 이후에 사용하는 테이블의 필드에서 인덱스를 확인해야합니다.

if(select count(1) from t where something= something) = 1 
begin 
    insert into A from t where something= something 
end 

이것은 나쁜 방법입니다 : 또한 내가 좋아하는 같은 구문을 참조하십시오. 다음과 같이 사용하십시오.

begin tran 
     insert into A from t where something= something 
if @@rowcount > 1 -- this is you requirement that needs just one row needs instead of if(select count(1) from t where something= something) = 1 
    rollback tran 
else 
    commit tran 

이 경우 두 개가 아닌 select이됩니다. 이 같은 경우 나는 것은 많은 변화가 조심스럽게

또한, 당신이

set statistics time on 
go 
set statistics io on 
go 

클라이언트 통계 (I/O 및 시간)을 포함 할 경우 greate 성능을 얻을 것이다 그리고 당신은 표시되는 내용 천천히 쿼리 작업의 일부입니다.

+0

나는 이것을 지금 시도 할 것이다 – Zingo

+0

이 방법은 지금까지 더 오래 걸렸다 – Zingo

+0

정말 색인이 존재하는지 확인합니까? 고객 통계의 일부를 보여줄 수 있습니까? –

0

모든 IF 구조 chrPgmCode에 체크 @tempTable

의미

tblActgPayeeTransactionAccounts2 경우 및 상기 데이터를 통과 한 정도로 경우 열당 열을 검사 할 필요가 없기

IF (Select COUNT(intActgAcctID) 
From dbo.tblActgPayeeTransactionAccounts2 as A INNER JOIN @tempView as V 
    ON A.chrPgmCode = V.chrPgmCode 
    where V.viewID = @Iterator) = 1 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (Select A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     From dbo.tblActgPayeeTransactionAccounts as A INNER JOIN @tempView as V 
     ON A.chrPgmCode = V.chrPgmCode 
     where V.viewID = @Iterator) 
END 
ELSE 
BEGIN 
    INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
     (SELECT NULL,NULL,NULL,NULL,NULL,NULL,V.chrPgmCode,V.intCarrierCode, V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
     FROM @tempView as V 
     where V.viewID = @Iterator) 
END 

동등 tblActgPayeeTransactionAccounts 은 동일한 데이터를가집니다.이 데이터는

INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
SELECT A.inbAcctgID,A.chrCarrierDesc,A.chrCarrierDescSht,A.intAcctCustID,A.intAcctCo,A.intAcctCoRec,A.chrPgmCode,A.intCarrierCode,V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
FROM dbo.tblActgPayeeTransactionAccounts as A 
    INNER JOIN @tempView as V ON A.chrPgmCode = V.chrPgmCode 

INSERT INTO @tempTable (inbAcctgID,chrCarrierDesc,chrCarrierDescSht,intAcctCustID,intAcctCo,intAcctCoRec,chrPgmCode,intCarrierCode,chrDlrNum,chrCvgCode,chrPayeeType,chrFeeType,intPayeeCode,chrTransType,Count,Amount) 
SELECT NULL,NULL,NULL,NULL,NULL,NULL,V.chrPgmCode,V.intCarrierCode, V.chrDlrNum,V.chrCvgCode,V.chrPayeeType,V.chrFeeType,V.intPayeeCode,V.chrTransType,V.Count,V.Amount 
FROM @tempView as V 
where NOT EXISTS (SELECT 1 
        FROM dbo.tblActgPayeeTransactionAccounts as A 
          INNER JOIN @tempView as V ON A.chrPgmCode = V.chrPgmCode 
       ) 

커서 또는 반복자 없음

+0

은 chrPgmCode ISNT와 동일합니다. 임시 테이블에 전달하기에 충분합니다. – Zingo

+0

그냥 실행했는데 약 1 분이 걸렸습니다. 처음에 테이블을 반환했습니다. – Zingo

+0

@Zingo 테스트 데이터가 없으면 말할 수 없습니다. 왜,'tblActgPayeeTransactionAccounts'의 모든 행이 필터링 된 viewMonthendArchiveGroupByCovg에 일치하는지 알 수 있기 때문에 일치하는 데이터와 일치하지 않는 SQLFiddle을 만들 수 있다면 확인해 볼 것입니다 – Serpiton

관련 문제