0

我有一个执行 2 次更新的存储过程,但我只想在参数@active等于时进行第一次更新'Y'

alter procedure sp_updateThis
@something varchar(5),
@active char(1)
as begin
-- check to see if active and do the update
update myTable set this=@something

-- run this one regardless
update yourTable set that=@something
4

4 回答 4

4

尝试用这个改变最后一行:

if (@active = 'Y')
begin
    update yourTable set that=@something
end
于 2013-03-01T19:48:52.263 回答
2
alter procedure sp_updateThis
@something varchar(5),
@active char(1)
as begin
-- check to see if active and do the update
if(@active = 'Y')
Begin
update myTable set this=@something
End

-- run this one regardless
update yourTable set that=@something
于 2013-03-01T19:50:35.350 回答
1

如果您真的想更新表中的每一行:

update myTable set this=@something where @active = 'Y';

否则你可能想要额外的条款......

于 2013-03-01T19:50:44.083 回答
0

你可以像这样创建一个过程: create procedure sp_updateThis @something varchar(5), @active char(1) AS Begin

if @active ='y' begin update yourTable set that=@something end else update myTable set this=@something update yourTable set that=@something

结束

于 2013-03-06T12:13:55.203 回答