救命!帮我看看这个是什么问题
刚刚学存储过程,在查询分析器里运行通过,但是StudentInfo里没有被更新
存储过程:
CREATE PROCEDURE Myupdate
@Scorename varchar(20),
@Score numeric(5),
@SuID int
as
begin
BEGIN TRANSACTION
update StudentInfo set @Scorename=@Score where SI_ID_N=@SuID
IF @@Error <> 0
goto Errorhandle
COMMIT TRANSACTION
RETURN 0
Errorhandle:
ROLLBACK TRANSACTION
RETURN 1
end
GO
测试:
Declare @Scorename varchar(20)
Declare @Score numeric(5)
Declare @SuID int
set @Scorename= 'score1 '
set @Score=8
set @SuID=3
exec Myupdate @Scorename,@Score,@SuID
------解决方案--------------------不好意思,再試下
Declare @S Varchar(8000)
Select @S= 'update StudentInfo set ' +@Scorename + ' = ' + Rtrim(@Score) + ' where SI_ID_N= ' + Rtrim(@SuID)
EXEC(@S)