请熟悉存储过程的大神帮帮忙
我想写一个存储过程.用来update某个表,把里面的RecId这列的前缀都改变,表是作为参数传入存储过程.原前缀,新前缀都是作为参数传进来
例如:
RecId
aa00001
aa00002
aa00003
全部改为
bb00001
bb00002
bb00003
ALTER PROCEDURE [dbo].[ModifySeq] @ProTableName varchar(20), @NewPrefix varchar(5), @Prefix varchar(5), ASbegin exec ('UPDATE '+ @ProTableName + 'set RecId=REPLACE('+@ProTableName+'.RecId '+','+ @Prefix+','+@NewPrefix+')') END
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'ModifySeq')BEGIN DROP PROC ModifySeqENDGOCREATE PROCEDURE [dbo].[ModifySeq] @ProTableName varchar(20), @NewPrefix varchar(5), @Prefix varchar(5) ASbegin EXEC ('UPDATE '+ @ProTableName + ' set RecId=REPLACE('+@ProTableName+'.RecId '+','+ '''' + @Prefix+ '''' + ','+ '''' + @NewPrefix + '''' +')') ENDGO