如何通过存储过程 return 更新和以前的值?

how to return updated and previous value through a stored procedure?

需要有关作业的帮助: 编写一个存储过程,以 EID 和 CITY 作为参数,并更新给定 EID 的员工所在的城市。更新城市后,您必须显示员工的旧城市和新城市以及 his/her name.I 尝试了以下已成功执行一半的部分

`create proc latest(@eid int, @city varchar(10))

AS

开始

update employee set city=@city where @eid=eid

结束

执行最新的 12,'rawalpindi'`

在更新之前存储原始值。类似于:

declare @previouscity varchar(10)
set @previouscity = (select city from employee where eid=@eid)

然后你进行更新,最后的事情是这样的:

select name + ' changed city from ' + @previouscity + ' to ' + city
from employee
where eid=@eid

全部未测试

使用更新语句的 output 子句。

update employee
set    city = @city
output ...
where  eid = @eid

我不会为你写出准确的输出语句。做你的作业! :)