试图创建更干净的SQL语法

Jam*_*son 2 sql t-sql sql-server

这是我想要做的:

select * from table
where in ('completedDate', 'completedBy', 'cancelDate', 'cancelBy') is not null
Run Code Online (Sandbox Code Playgroud)

如果上面的四列不是null,我需要显示记录.我知道我会用几个where /和子句来做这个,但是试着学习并让我的新东西更干净.

我想以更清洁的方式做到这一点吗?

jod*_*ods 6

如果我理解正确,我想你想这样做:

select * 
from table
where completedDate is not null
  and completedBy is not null
  and cancelDate is not null 
  and cancelBy is not null
Run Code Online (Sandbox Code Playgroud)

关于代码的清晰度,我没有看到更好的编写方式,这就是我要编写的代码.

编辑:在这种情况下,我不会那样做,但如果这是一个非常常见的情况,你可以在表中添加一个计算列(存储或不存储),或在表的顶部创建一个视图,并执行:

select * from view where importantFieldsAreNotNull = 1
Run Code Online (Sandbox Code Playgroud)