首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQL Server 2005存储过程问题

SQL Server 2005存储过程问题
EN

Stack Overflow用户
提问于 2011-06-20 14:40:12
回答 1查看 66关注 0票数 0

我正在编写一个存储过程,如下所示:

代码语言:javascript
复制
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),所以我将基于AccountTypeID = 10 and 20比较这两个accountnumbers (1000, 10003, 1006)

请告诉我如何编写存储过程?

谢谢

赫曼思

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-20 14:44:43

使用IN而不是=

代码语言:javascript
复制
...
where
    CustomerID=@CustomerID
    or
    CustomerID=''
    and
    AccountNumber IN  (select AccountNumber from tblInvAccountDetails where AccountTypeID IN (10, 20))

注意:

  • AccountTypeID不能同时为10和20 :我假设您的意思是OR。IN是multiple OR
  • 的缩写,优先于OR,因此请检查您是否需要在某个地方使用()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6407651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档