如何将以下代码重写为sql.
我需要根据我的新'item'
'newcol'
代码是。
select
s.code,
o.[work name],
case when o.[work name] is null
then s.code
else o.[work name]
end newcol,
item=(select item from table1 where table1.code=newcol)
from
shoplog s
left outer join odc o on o.barcode=s.code
答案 0 :(得分:1)
您可以使用sub-query
来实现您的需求。
select a.code, a.[work name], a.newcol, b.code as item
from
(select
s.code,
o.[work name],
case when o.[work name] is null
then s.code
else o.[work name]
end newcol
from
#shoplog s
left outer join #odc o on o.barcode=s.code
)a
inner join
#table1 b
on (a.newcol = b.code)