我目前有一个select语句,用于检查几列以查看它们是否有数据。如果它们中的任何一个都是空的,那么我需要一些设置为false。如果他们都不是null,那么我想要一点设置为true。这是我目前有:确定是否有值为空,如果为true,则返回false,否则为true
select
cast(
case when ChangeOrderNumber is null then 0 else 1 end *
case when ClientName is null then 0 else 1 end *
case when QuoteNumber is null then 0 else 1 end *
case when ClientNumber is null then 0 else 1 end *
case when ServiceLine is null then 0 else 1 end *
case when ServiceLineCode is null then 0 else 1 end *
case when GroupLeader is null then 0 else 1 end *
case when CreatedBy is null then 0 else 1 end *
case when PTWCompletionDate is null then 0 else 1 end *
case when BudgetedHours is null then 0 else 1 end *
case when BudgetDollars is null then 0 else 1 end *
case when InternalDeadlineDate is null then 0 else 1 end *
case when ProjectDescription is null then 0 else 1 end *
case when Sales is null then 0 else 1 end *
case when Coop is null then 0 else 1 end *
case when PassThrough is null then 0 else 1 end *
case when POStatus is null then 0 else 1 end *
case when PONumber is null then 0 else 1 end as bit
)
as Flag
from t
现在,该代码的作品,但它是一个有点冗长,如果有人知道的更好的方法来做到这一点,我想知道。请注意有几种数据类型正在被检查。
更多详细信息: 此代码位于处理更改订单的应用程序中正在查看的视图中。在可以处理变更单之前,它必须符合一些数据质量检查。此视图显示是否有任何所需的数据为空。
来吧大卫......你不知道如何做到这一点:P – SQLMenace 2011-05-24 20:19:59