【发布时间】:2021-04-25 09:14:02
【问题描述】:
在我的 SQL 语句中,如果 Type 的值等于“T”,那么我想添加一个条件 OR 子句,如下所示。否则,将没有 OR 子句
if type not equal to 'T':
select customerid, type from customer
where cityid = '20'
if type is equal to 'T'
select customerid, type from customer
where cityid = '20' OR cityid = '5'
【问题讨论】:
-
旁白:
cityid真的是字符串吗?您的代码将其与字符串 ('20') 而非int(20) 值进行比较。 -
是的,cityid 是一个字符串。
-
type是表中的列还是代码中的变量(@type)? -
@Kim 以下答案之一是否解决了您的问题?如果是这样,请考虑接受它。如果没有,请向我们提供更多信息。
标签: sql sql-server tsql logical-operators