2011-06-20 45 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是多个手术室
  • 的简写,其优先级,如果你需要()地方