Вам нужно вложить это в другой CASE
.
CASE WHEN
CASE
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Run%'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Pure'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Team%'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
ELSE dbo.WorkOrderDetails.QtyOrdered
END
< 5
THEN 'Car'
ELSE 'VAN'
END as NewCol
Или другой способ - использовать CTE
.
;with cte as(
select *,
CASE
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Run%'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Pure'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Team%'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
ELSE dbo.WorkOrderDetails.QtyOrdered
END as NumberofItems
from ItemSpecs)
select *,
case when NumberofItems < 5 then 'car' else 'van' end as NewCol
from cte
Или в виде производной таблицы
select
col1,
col2,
case when NumberofItems < 5 then 'car' else 'van' end
from
(select *,
CASE
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Run%'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Pure'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
WHEN dbo.ItemSpecs.ConfigProptext LIKE 'Team%'
THEN (CEILING(dbo.WorkOrderDetails.QtyOrdered / 4))
ELSE dbo.WorkOrderDetails.QtyOrdered
END as NumberofItems
from ItemSpecs) x