日期:2014-05-18  浏览次数:20501 次

请帮忙改个存储过程
CREATE   PROCEDURE   dbo.SaveSpeed
@TableName   varchar(80)   =   NULL,  
@Speed1     float   =   NULL,        
@Speed2   int       =   NULL,
@fTime     float   =   NULL,
@iIndex   int       =   NULL
AS

IF   @TableName   IS   NULL   or   @Speed1   IS   NULL   or   Speed2   IS   NULL   or   fTime   IS   NULL   or   iIndex   IS   NULL
BEGIN
      PRINT   'ERROR:   You   must   specify   a   value. '
      RETURN
END

--   INSERT   the   alert   value   to   the   specified   Table.
INSERT   INTO   [str(TableName)]     VALUES   (@Speed1,@Speed2,@fTime,@iIndex)

RETURN
GO

这个存储过程在检查语法时提示错误,请大家帮忙改一下,谢了。

------解决方案--------------------
CREATE PROCEDURE dbo.SaveSpeed
@TableName varchar(80) = NULL,
@Speed1 float = NULL,
@Speed2 int = NULL,
@fTime float = NULL,
@iIndex int = NULL
AS

IF @TableName IS NULL or @Speed1 IS NULL or Speed2 IS NULL or fTime IS NULL or iIndex IS NULL
BEGIN
PRINT 'ERROR: You must specify a value. '
RETURN
END

-- INSERT the alert value to the specified Table.
declare @s varchar(8000)
set @s= 'insert into '+@tablename+ ' select ' +rtrim(@Speed1)+ ', '+rtrim(@Speed2)+ ', '+rtrim(@fTime)+ ', '+rtrim(@iIndex)
exec(@s)

RETURN
GO


------解决方案--------------------
CREATE PROCEDURE dbo.SaveSpeed
@TableName varchar(80) = NULL,
@Speed1 float = NULL,
@Speed2 int = NULL,
@fTime float = NULL,
@iIndex int = NULL
AS

IF @TableName IS NULL or @Speed1 IS NULL or @Speed2 IS NULL or @fTime IS NULL or @iIndex IS NULL
BEGIN
PRINT 'ERROR: You must specify a value. '
RETURN
END

-- INSERT the alert value to the specified Table.
declare @sql varchar(8000)
set @sql = 'insert ' + @TableName + 'values ( '+ cast(@Speed1 as VARCHAR(20)) + ', ' +cast(@Speed1 as VARCHAR(20))+ ', '+cast(@fTime as VARCHAR(20)) + ', '+ cast(@iIndex as VARCHAR(20)) + ') '

exec(@sql)

RETURN
GO
------解决方案--------------------
select * from [20070905150026]