CREATE PROCEDURE dbo.SaveSpeed
@TableName varchar(80) = NULL, 
@Speed1  float = NULL,    
@Speed2 int   = NULL,
@fTime  float = NULL,
@iIndex int   = NULL
ASIF @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这个存储过程在检查语法时提示错误,请大家帮忙改一下,谢了。

解决方案 »

  1.   

    CREATE PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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
      

  2.   

    yrwx001,你能测试一下再贴上来吗?你的也有错误。
      

  3.   

    CREATE PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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
      

  4.   

    CREATE PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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
      

  5.   

    CREATE PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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
      

  6.   

    Speed2,fTime,iIndex前面应该加个@符号
      

  7.   

    CREATE PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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
      

  8.   

    Speed2,fTime,iIndex前面应该加个@符号
    -------------------------
    正解,
      

  9.   

    "Speed2,fTime,iIndex前面应该加个@符号"这个错误已改过来了,现在已无语法问题,可是还是无法执行成功啊!按我的方法在[str(@TableName)] 处提示"对象名 'str(@TableName)' 无效。"
    直接用[@TableName]也不行。按ojuju10的方法也在@TableName提示错误,我的TableName是有数字存在的,提示"第 1 行: '20070905150026' 附近有语法错误。"
      

  10.   

    use  testdrop table erdgzw
    Create table erdgzw 
    (
    Speed1 float,
    Speed2 float,
    fTime int,
    iIndex int
    )alter  PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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 into  ' + @TableName+ '  values ('+cast(@Speed1 as varchar(10))+',' +cast(@Speed2 as varchar(10))+','+cast(@fTime as varchar(10))+','+cast(@iIndex as varchar(10))+')'
    print @sql
    exec(@sql)RETURN
    GO
    exec dbo.SaveSpeed  'erdgzw', '11.01', '11', '11.10' ,'11'select * from erdgzw
    ------------------------------------------------11.01 11.0 11 11
      

  11.   

    use  testdrop table [20070905150026]
    Create table  [20070905150026]
    (
    Speed1 float,
    Speed2 float,
    fTime int,
    iIndex int
    )
    create   PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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 into  ' + @TableName+ '  values ('+cast(@Speed1 as varchar(10))+',' +cast(@Speed2 as varchar(10))+','+cast(@fTime as varchar(10))+','+cast(@iIndex as varchar(10))+')'
    print @sql
    exec(@sql)RETURN
    GO
    exec dbo.SaveSpeed  '[20070905150026]', '11.01', '11', '11.10' ,'11'select * from erdgzw
      

  12.   

    select * from [20070905150026]
      

  13.   

    fwacky你的例子能成功,可是现在的关键是我要添加记录的表名前为数字,如'123erdgzw'这样的,所以用你的办法还是不行。
      

  14.   

    不行不行,
    执行
    exec SaveAlert '[20070905150026]','136.922941277777','3000','39330.6253096065','11'结果为:
    insert into  [20070905150026]  values (136.923,3000,39330.6,11)数据类型转换错误!
    '136.922941277777'变成了136.923
    怎样才能全精度保存
      

  15.   

    CREATE PROCEDURE dbo.SaveSpeed
    @TableName varchar(80) = NULL, 
    @Speed1  float = NULL,    
    @Speed2 int   = NULL,
    @fTime  float = NULL,
    @iIndex int   = NULL
    ASIF @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  '+rtrim(@tablename)+' select ' +rtrim(@Speed1)+','+rtrim(@Speed2)+','+rtrim(@fTime)+','+rtrim(@iIndex)
    exec(@s)RETURN
    GO
      

  16.   

    现在是数据精度的问题执行
    exec SaveSpeed '[20070905150026]','136.922941277777','3000','39330.6253096065','11'结果为:
    insert into  [20070905150026]  values (136.923,3000,39330.6,11)数据类型转换错误!
    '136.922941277777'变成了136.923
    怎样才能全精度保存