编写多事例SQL语句的更好方法
我下面有个问题。我正试图找到一种更好的方法来编写这个包含语句的查询。我不想将每个case值存储在temp表中,但可能存储在数组中。。有什么意见吗编写多事例SQL语句的更好方法,sql,Sql,我下面有个问题。我正试图找到一种更好的方法来编写这个包含语句的查询。我不想将每个case值存储在temp表中,但可能存储在数组中。。有什么意见吗 SELECT [coll_desc], [coll_descF], [coll_descS], [collcode], [agencystat], [nosend], [expiredays], [tier],
SELECT
[coll_desc],
[coll_descF],
[coll_descS],
[collcode],
[agencystat],
[nosend],
[expiredays],
[tier],
[Available],
case when([collcode] = 'PIE') then CAST(0 AS BIT)
when([collcode] = 'PIF') then CAST(0 AS BIT)
when([collcode] = 'PND') then CAST(0 AS BIT)
when([collcode] = 'PPA') then CAST(0 AS BIT)
when([collcode] = 'PPD') then CAST(0 AS BIT)
when([collcode] = 'RCL') then CAST(0 AS BIT)
when([collcode] = 'RES') then CAST(0 AS BIT)
when([collcode] = 'SIF') then CAST(0 AS BIT)
when([collcode] = 'SSC') then CAST(0 AS BIT)
when([collcode] = 'SSP') then CAST(0 AS BIT)
when([collcode] = 'HLD') then CAST(0 AS BIT)
else CAST(1 AS BIT)
end as [fin_hold]
FROM [dbo].[collcode_Agency_Codes] WITH (NOLOCK)
WHERE type = 'APR'
你能满足你想做的事吗
(case when(collcode IN ('PIE', 'PIF', 'PND', . . .) then CAST(0 AS BIT)
else CAST(1 AS BIT)
end)
它当然缩短了代码