2017-08-10 217 views
-1

我正在编写存储过程以更新基于列或其他表格。 这是我有:在case语句后编写JOIN语句

Set Foutcome Case when Tp is > 0 and Rr = 0 
     Then 'settled' 
     Else 
     update a set a.Fouctome = b.outcome 
     From table_a innerjoin table_b 
     On a.datasource= b.datasource 
where datasource like '%Bong%' 

但它不起作用。请帮忙。

+0

似乎你的sql语句无效。首先设置你分配一个值作为“定居”,那么其他人进入你的取景另一个更新语句是无效的。 – Oasis

+0

添加一些示例表数据和预期的结果 - 所有的格式化文本。 – jarlh

回答

0

尝试下面的SQL。

update a 
set Foutcome= 
case when Tp is > 0 and Rr = 0 then 'settled' 
else (select top 1 b.outcome from b 
     inner join a on a.datasource= b.datasource 
     where b.datasource like '%Bong%') 
end 
+0

它只会从else部分中选择一个值。但是在OP中他试图更新数据源如'Bongo'的所有记录 – Oasis

+0

@Oasis ok,也许我误解了他,如果是这样,我会稍后更新答案。 – Nico