---
# System prepended metadata

title: 效能提升
tags: [SQL]

---

---
tags: SQL
authors: Anderson
---

###### tags: `SQL`
# 效能提升

## :memo: 調整前
```sql=
~(略)~
Where RR.ID between @ReplacementID1 And @ReplacementID2 
	And po3.id is not null
    And not exists(
            Select Top 1 1 
            From dbo.ShipPlan_Detail 
            Where ID = @ID And PoID = RR.POID And Seq1 = RRD.Seq1 And Seq2 = RRD.Seq2 And duty = '6'
        ) 
```
<p style="color:red;font-weight:bold;">執行後結果:</p>

![](https://i.imgur.com/GrMvRCW.png)


## :memo: 調整後
將 `po3.id is not null` 更改為 `Isnull(po3.id, '') <> ''`

```sql=
~(略)~
Where RR.ID between @ReplacementID1 And @ReplacementID2 
	And Isnull(po3.id, '') <> ''
    And not exists(
            Select Top 1 1 
            From dbo.ShipPlan_Detail 
            Where ID = @ID And PoID = RR.POID And Seq1 = RRD.Seq1 And Seq2 = RRD.Seq2 And duty = '6'
        ) 
```
<p style="color:red;font-weight:bold;">執行後結果:</p>

![](https://i.imgur.com/WtoxXLx.png)