存储过程如下:
CREATE PROCEDURE [dbo].[P_Public_ModOne]
(
@id INT,
@table VARCHAR(50),
@key VARCHAR(50),
@filed VARCHAR(50),
@values VARCHAR(50)
)
AS
BEGIN
DECLARE @sql VARCHAR(8000)
SET @sql = 'UPDATE ['+ @table +'] SET ['+ @filed +'] = '+ CAST(@values AS VARCHAR(50)) +' WHERE ['+ @key +'] = '+ CAST(@id AS VARCHAR(10)) +''
EXEC(@sql)
END
数据表如下:
create table users
(
u_id int identity(1,1),
u_name varchar(50)
)
执行存储过程如下:
exec P_Public_ModOne 1,'users','u_id','u_name','123'
这个语句没有问题,但是下面的语句问题出现了:
exec P_Public_ModOne 1,'users','u_id','u_name','sa'
提示错误:列名'sa'无效!
两条语句的区别在于:
前者是要把u_name改为数字'123',后者则是把u_name改为字母'sa'.
百思不得其解,不知道问题在哪里,特来求教!!!
exec P_Public_ModOne 1,'users','u_id','u_name','''sa'''
试试
是的.已经是Varchar类型了,不需要再做转换