sql存储过程中加引号
ALTER PROCEDURE [dbo].[SaveTerminaInfo]
@TerminaNo NVARCHAR(50),
@Name NVARCHAR(50),
@Value NVARCHAR(500)
AS
BEGIN
DECLARE @Sql NVARCHAR (MAX)
SET NOCOUNT ON;
if NOT exists(select * from syscolumns where id=object_id('终端信息') and name=@Name)
BEGIN
SET @Sql = N'ALTER TABLE 终端信息 ADD ' + @Name + ' NVARCHAR(50)';
EXEC(@Sql);
PRINT @Sql;
END
SET @Sql = N'UPDATE 终端信息' + ' SET '+ quotename(@Name) +' = ' + ''''+ @Value + '''' + ' WHERE 编号' +' = ' + ''''+ @TerminaNo +''''
EXEC(@Sql);
END
GO
执行如下:
EXEC [dbo].[SaveTerminaInfo]
@TerminaNo ='31',
@Name='工号',
@Value='syl'