sql一表tb,有name title.现 张一 null 王二 null 将title 中的值改成相应姓呢???用这句sql为什么不对?
update tb set if (exists(select c1 from tb where c1 like '张_'))
begin title='张' end
else begin title='王' end
-------这样不行哦,怎么才能利用if true_false begin --sql1 end else begin sql2 end
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'if'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'tb'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'tb'.
------解决方案--------------------
不能用if 只能用case when