-1
WHERE CompanyId=@CompanyId
or
P.ProductId=1
or
C.CustomerSituation=1

如果CompanyId必须如下所示(必填)

我想要像下面这样的东西。

Where

AND CompanyId=@CompanyId // Question here

Or P.ProductId=1
Or C.CustomerSituation=1

CompanyId必须是和(需要 %100)其他值是或。

我怎样才能给“和”CompanyId

4

3 回答 3

1

使用括号指定优先级

Where

CompanyId=@CompanyId // Question here
AND (
   Or P.ProductId=1
   Or C.CustomerSituation=1 )
于 2013-10-21T12:52:31.630 回答
1
Where
CompanyId=@CompanyId // Question here
AND
(P.ProductId=1 OR C.CustomerSituation=1)
于 2013-10-21T12:52:11.237 回答
1

我只有 40% 确定你在这里问什么;我假设,该确切的字符串AND CompanyId=@CompanyId必须出现在查询中,因为您正在构建从网页或其他内容生成的动态查询。

Where 1=1
    and CompanyId=@CompanyId
    and (1=2
        Or P.ProductId=1
        Or C.CustomerSituation=1
    )
于 2013-10-21T12:56:14.110 回答