存储过程条件更新有关问题
存储过程条件更新问题
------最佳解决方案--------------------
update Contact set B=cast(cast(B as int)+@B as varchar(50)) where ...
------其他解决方案--------------------
update Contact set B=B+@B where ...
------其他解决方案--------------------
如果都是字符型,的话,如果变成整型就需要cast一下。
------其他解决方案--------------------
update Contact set B=cast(cast(B as int)+@B as varchar(50)) where ... 同意上面这位
------其他解决方案--------------------
update Contact set B=cast(cast(B as int)+@B as varchar(50))where ...
------其他解决方案--------------------
ALTER procedure [dbo].[Pro_1]
@A varchar(50),
@B varchar(50),
@C datetime, --日期格式
@Remark1 varchar(50),
@Remark2 varchar(50)
as
begin
if exists(select 1 from Contact where [A]=@a and [c]=@c)
begin
return 0--现在这里需要写成更新
--update Contact set B+=@B where ... --这里更新语句该怎么写呢?将字段B累加上传过来的参数@B(B在表中是字符类型)
end
else
begin
insert into Contact([A],[B],[C],[Remark1],[Remark2])
Values(@A,@B,@C,@Remark1,@Remark2)
return 1--表示成功
end
end
------最佳解决方案--------------------
update Contact set B=cast(cast(B as int)+@B as varchar(50)) where ...
------其他解决方案--------------------
update Contact set B=B+@B where ...
------其他解决方案--------------------
如果都是字符型,的话,如果变成整型就需要cast一下。
------其他解决方案--------------------
update Contact set B=cast(cast(B as int)+@B as varchar(50)) where ... 同意上面这位
------其他解决方案--------------------
update Contact set B=cast(cast(B as int)+@B as varchar(50))where ...
------其他解决方案--------------------
update Contact set B=cast(cast(B as int)+@B as varchar(50)) where ...