2016-01-12 100 views
0

誰能幫我修改下面的子查詢到加盟條件,使我們可以提高腳本更改子查詢到加盟條件

from #Head   hw 
     join Employee   et 
     on hw.EmployeeCode = et.EmployeeCode 
     and et.BonusFlag  = 1 
     join Bonus   cb 
     on hw.BonusId    = cb.BonusId 
     and cb.CompanyId   = @CompanyId 
     join bonus b 
     on hw.BonusId    = b.BonusId 
     join Expense  pr 
     on pr.CompanyId   = @CompanyId 
     and pr.ModuleId   = b.ModuleId 
    Where hw.BucketId  = @BucketId 
     and upper (et.EmployeeCode)  <> 'H' 
     and hw.bucketcode not in (Select centercode from NExclusion) 
+0

請學會使用正確的'JOIN'語法。從不在'FROM'子句中使用逗號。 *始終*使用正確的顯式'JOIN's。 –

回答

0
from #Head hw 
    join NExclusion on NExclusion.centercode = hw.bucketcode 
    join Employee et on hw.EmployeeCode = et.EmployeeCode 
    join Bonus b on hw.BonusId = b.BonusId 
    join Expense pr on pr.CompanyId = @CompanyId and pr.ModuleId = b.ModuleId 
    Where hw.BucketId = @BucketId and et.BonusFlag = 1 and b.CompanyId = @CompanyId and et.EmployeeCode <> 'h' 

的表現我做了以下修改:
1)將所有條件移到where子句後面的最後一個地方。
2)Sql不區分大小寫,因此您不需要將EmployeeCode轉換爲大寫並進行比較,我已經將其刪除以降低此性能開銷。
3)改變IN條件加入。 4)刪除了獎勵表的重複連接