2012-10-24 31 views
0

可否請您讓我知道如果存儲過程允許處理如下複合條件:複合條件存儲過程

if(
    ((select Count(*) from dbo.Membership where [email protected]) >0) 
            || 
    ((select Count(*) from dbo.Allocation where [email protected])>0)) 
) 
+0

當我嘗試編譯存儲過程中,我收到錯誤消息。 –

+1

**請**讓我們知道**究竟是什麼**你得到的錯誤信息..... –

+1

看起來你的括號對我來說並不平衡。你有一個額外的')' –

回答

5

使用OR而不是||

更優化的,如果只是檢查存在,我會使用EXISTS而不是COUNT,因爲它會在第一次存在時停止,而不是將它們全部計數...

IF EXISTS(SELECT 1 FROM dbo.Membership WHERE EmailId = @emailID) 
    OR EXISTS(SELECT 1 FROM dbo.Allocation where [email protected]) 
    BEGIN 
     -- emailID exists in one of the 2 tables 
    END 
+0

優秀!並感謝提示。它像一個魅力。 –