Sql server 2008 使用SQLServer2008,我有一个硬编码的两层case语句,我希望将其放入参考表中

Sql server 2008 使用SQLServer2008,我有一个硬编码的两层case语句,我希望将其放入参考表中,sql-server-2008,case,Sql Server 2008,Case,使用SQL Server 2008查询预约数据。 预约持续时间基本上是硬编码的,具体取决于诊所和预约类型,如下示例所示: case when cl.ClinicCode like 'FPLAS%' then case when apt.AppointmentTypeName in ('New','Time Critical','Emergency') then 20 else 10 end when cl.ClinicCode like 'SPLAS%' then case when a

使用SQL Server 2008查询预约数据。 预约持续时间基本上是硬编码的,具体取决于诊所和预约类型,如下示例所示:

case when cl.ClinicCode like 'FPLAS%' then case when apt.AppointmentTypeName in ('New','Time Critical','Emergency') then 20 else 10 end
    when cl.ClinicCode like 'SPLAS%' then case when apt.AppointmentTypeName in ('New','Time Critical','Emergency') then 20 else 10 end
else 30 end as duration 

我想删除编码并创建一个表来存储此信息。我的问题是apt.AppointmentTypeName大约有50个潜在值,我不想对400个不同的代码中的每一个重复这些值。如何最好地处理嵌入式AppointTypeName案例语句的“else”部分

只要储存你想要的。任何不匹配的内容都返回NULL。将此空值转换为30

我有很多假设。如果你把你所有的代码都发出去,我可以赚更少的钱

SELECT ISNULL(AppointmentTime.Duration,30) As Duration
FROM YourTable
LEFT OUTER JOIN
AppointmentTime
ON cl.ClinicCode LIKE AppointmentTime.Lookup1
AND apt.AppointmentTypeName = AppointmentTime.Lookup2
您可能还希望将此默认值30存储在同一个表中