将案例陈述结果与
Combine case statement result with
我有一个以 3 开头的值需要转换,然后将该值与另一个字段组合以创建最终值。
到目前为止的代码:
,case
when b.thing like '3%' then '000'
else b.thing
end as 'Thing'
然后我想使用 'Thing' 值来创建 'Thing+b.Stuff'。我试图将 'b.Stuff' 添加到 else 语句但只返回 'b.Thing'.
我想我可能需要创建一个 subquery/inline 视图,但我不知道该怎么做。
您应该可以将 b.stuff 添加到您的代码中(假设它们是相同的数据类型)
,case
when b.thing like '3%' then '000'+b.stuff
else b.thing+b.stuff
end as 'Thing'
我有一个以 3 开头的值需要转换,然后将该值与另一个字段组合以创建最终值。
到目前为止的代码:
,case
when b.thing like '3%' then '000'
else b.thing
end as 'Thing'
然后我想使用 'Thing' 值来创建 'Thing+b.Stuff'。我试图将 'b.Stuff' 添加到 else 语句但只返回 'b.Thing'.
我想我可能需要创建一个 subquery/inline 视图,但我不知道该怎么做。
您应该可以将 b.stuff 添加到您的代码中(假设它们是相同的数据类型)
,case
when b.thing like '3%' then '000'+b.stuff
else b.thing+b.stuff
end as 'Thing'