我目前有一個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