在预期条件的上下文中指定的非布尔类型的表达式,靠近“END" [英] An expression of non-boolean type specified in a context where a condition is expected, near 'END'

查看:26
本文介绍了在预期条件的上下文中指定的非布尔类型的表达式,靠近“END"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以也许有人可以指出导致此错误的正确方向?我已经为此奋斗了几个小时并在网上搜索,但我无法弄清楚我在这里做错了什么.它作为存储过程的一部分包含在内,我不知道这是否重要,如果确实如此,我也可以将其包含在内.表和字段名称已更改以保护无辜者……这意味着我的工作.谢谢.

So maybe someone can point me in the right direction of what is causing this error? I've been fighting with this for a couple of hours and searching the web, and I can't figure out what I'm doing wrong here. It's included as part of a stored procedure, I don't know if that matters, if it does I can include that as well. Tables and field names have been changed to protect the innocent... meaning my job. Thanks.

SELECT
              /* The fields are here*/
FROM
              /* my joins are here */
WHERE
    (Table.Field = stuff)
    AND
    (Table.Field2 = otherstuff)
    AND
    (Table2.Field3 = someotherstuff)
    AND
    CASE @param1
        WHEN 0 THEN 'Table.Field IS NULL'
        WHEN 1 THEN 'Table.Field2 IS NOT NULL'
        ELSE ''
    END

感谢您的回复.从技术上讲,egrunin 是这个问题的正确答案,但 OMG Ponies 和 Mark Byers 几乎是一样的东西,只是缺少最后一部分.再次感谢.

推荐答案

我很确定其他答案遗漏了一个案例:

I'm pretty sure the other answers leave out a case:

WHERE 
(Table.Field = stuff)
AND
(Table.Field2 = otherstuff)
AND
(Table2.Field3 = someotherstuff)
AND
(
    (@param1 = 0 and Table.Field IS NULL)
    OR
    (@param1 = 1 and NOT Table.Field2 IS NULL)
    OR
    (@param1 <> 0 AND @param1 <> 1) -- isn't this needed?
)

这篇关于在预期条件的上下文中指定的非布尔类型的表达式,靠近“END"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆