2011-06-20 84 views
0

我寫一個存儲過程是這樣的:SQL Server 2005的存儲過程的問題

create PROC uspInvCustomerLineItemGetList1(@CustomerID varchar(50)) 
AS 
BEGIN 
    SELECT LineItemID, LineItemName 
    from tblInvoiceLineItems 
    where CustomerID = @CustomerID 
     or CustomerID = '' 
     and AccountNumber = (select AccountNumber from tblInvAccountDetails 
          where AccountTypeID = 10 and 20) 

END 

我的問題是通過2個或多個值(select AccountNumber from tblInvAccountDetails where AccountTypeID = 10 and 20)所以我會比較子查詢都accountnumbers (1000, 10003, 1006)基於AccountTypeID = 10 and 20

如何我可以寫存儲過程嗎?

謝謝

hemanth

+1

歡迎StackOverflow上在左右檢查。請注意常見問題解答:http://meta.stackexchange.com/q/7237/27535 – gbn

回答

2

使用IN沒有=

... 
where 
    [email protected] 
    or 
    CustomerID='' 
    and 
    AccountNumber IN (select AccountNumber from tblInvAccountDetails where AccountTypeID IN (10, 20)) 

注:

  • AccountTypeID不能同時10和20在同一時間:我想你意味着或。 IN是多個手術室
  • 的簡寫,其優先級,如果你需要()地方