SQL 关于case的用法报错
declare @aa varchar(20)
declare @bb varchar(20)
declare @cc varchar(20)
set @bb='1215002'
select @aa=max(in_code) from accountant_subject where set_code='905008410001002' and in_code like @bb+'%' and len(in_code)=len(@bb)+3
print @aa
update accountant_subject set(@aa=case when @bb='1215002' then @aa+1)where set_code='905008410001002' and in_code like '126'+'%' and len(in_code)=len('126')+3
服务器: 消息 170,级别 15,状态 1,行 7
第 7 行: ')' 附近有语法错误。
报错是哪里错误啊 本人是菜鸟 希望高手指点下啊,希望实现的是在表中满足条件的话@aa加1
------解决方案--------------------
declare @aa varchar(20)
declare @bb varchar(20)
declare @cc varchar(20)
set @bb='1215002'
select @aa=max(in_code) from accountant_subject where set_code='905008410001002' and in_code like @bb+'%' and len(in_code)=len(@bb)+3
print @aa
update accountant_subject set
@aa=(case when @bb='1215002' then @aa+1 else 1 end)
where set_code='905008410001002' and in_code like ('126'+'%') and len(in_code)=len('126')+3
------解决方案--------------------case when then
else end
set(@aa=case when @bb='1215002' then @aa+1)
-->set @aa=
(case when @bb='1215002' then @aa+1
else xxx end )