CREATE PROCEDURE [InsertRoad]
@TableName[varchar](8),
@sTitle_p [varchar](50),
@sText_p [text]
AS INSERT INTO [TableName]
([sTitle],
[sText])
VALUES
(@sTitle_p,
@sText_p)
GO
================================================
想要在上面这个插入数据的存储过程中使用参数做表的名字,现在的写法是错误的,应该怎么改?
------解决方案--------------------------------------------------------
CREATE PROCEDURE InsertRoad
@TableName varchar (8),
@sTitle_p varchar (50),
@sText_p text
AS
DECLARE @SQL VARCHAR(1000)
SET @SQL= 'INSERT INTO '+@TableName+ '(sTitle,sText) VALUES( '+@sTitle_p+ ', '+@sText_p+ ') '
EXEC(@SQL)
GO
------解决方案--------------------------------------------------------
CREATE PROCEDURE [InsertRoad]
@TableName[varchar](8),
@sTitle_p [varchar](50),
@sText_p [text]
AS
declare @SQL nvarchar(1000)
set @SQL = 'INSERT INTO ' + @TableName + ' ([sTitle],[sText]) valuses( ' + @sTitle_p
+ ', ' + @sText_p + ') '
exec @SQL