0

ステージング テーブルにない #TempTable 内のすべてのレコードを検索しようとしています。比較は 16 のフィールドで行う必要があることに注意してください。

いくつかの組み合わせを試しましたが、何もうまくいかないようです。

    SELECT CustomerAccountNo FROM #TempTable        
    WHERE NOT EXISTS
    (SELECT e.[CustomerAccountNo] ,
    e.[MeterNo] ,
    e.[CustomerName1] ,
    e.[ServiceAddress1] ,
    e.[ServiceAddress2] ,
    e.[ServiceCity] ,
    e.[ServiceState] ,
    e.[ServiceZip] ,
    e.[BillingAddress1] ,
    e.[BillingAddress2] ,
    e.[BillingAddress3] ,
    e.[BillingCity] ,
    e.[BillingState] ,
    e.[BillingZip] ,
    e.[BillingZip4] ,
    e.[PrimaryPhoneNumber] FROM #TempTable e
    JOIN dbo.Staging s
    ON e.CustomerAccountNo = s.CustomerAccountNo AND
    e.MeterNo = s.MeterNo AND
    e.CustomerName1 = s.CustomerName1 AND
    e.ServiceAddress1 = s.ServiceAddress1 AND
    e.ServiceAddress2 = s.ServiceAddress2 AND
    e.ServiceCity = s.ServiceCity AND
    e.ServiceState = s.ServiceState AND
    e.ServiceZip = s.ServiceZip AND
    e.BillingAddress1 = s.BillingAddress1 AND
    e.BillingAddress2 = s.BillingAddress2 AND
    e.BillingAddress3 = s.BillingAddress3 AND
    e.BillingCity = s.BillingCity AND
    e.BillingState = s.BillingState AND
    e.BillingZip = s.BillingZip AND
    e.BillingZip4 = s.BillingZip4 AND
    e.PrimaryPhoneNumber= s.PrimaryPhoneNumber          
    )
4

3 に答える 3

0

正しい答えを得るには、より詳細な状況を提供する必要があります。

明らかに、FROM 句と WHERE 句の間に接続がないため、クエリはすべてを返します。

これを試してください:

SELECT CustomerAccountNo FROM #TempTable t       
WHERE NOT EXISTS
    (SELECT 1 FROM dbo.Staging s WHERE
    t.CustomerAccountNo = s.CustomerAccountNo AND
    t.MeterNo = s.MeterNo AND
    t.CustomerName1 = s.CustomerName1 AND
    t.ServiceAddress1 = s.ServiceAddress1 AND
    t.ServiceAddress2 = s.ServiceAddress2 AND
    t.ServiceCity = s.ServiceCity AND
    t.ServiceState = s.ServiceState AND
    t.ServiceZip = s.ServiceZip AND
    t.BillingAddress1 = s.BillingAddress1 AND
    t.BillingAddress2 = s.BillingAddress2 AND
    t.BillingAddress3 = s.BillingAddress3 AND
    t.BillingCity = s.BillingCity AND
    t.BillingState = s.BillingState AND
    t.BillingZip = s.BillingZip AND
    t.BillingZip4 = s.BillingZip4 AND
    t.PrimaryPhoneNumber= s.PrimaryPhoneNumber          
    )
于 2013-04-25T19:32:14.003 に答える