首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请帮忙改个存储过程解决方法

2012-03-09 
请帮忙改个存储过程CREATEPROCEDUREdbo.SaveSpeed@TableNamevarchar(80)NULL,@Speed1floatNULL,@Speed2i

请帮忙改个存储过程
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]

热点排行