ALTER PROCEDURE [dbo].[p_BloggerGraph_Insert_NO] 
-- Add the parameters for the stored procedure here 
@table nvarchar(40), 
        @bloggerID1 int, 
        @bloggerID2 int, 
        @weight float 
AS 
SET NOCOUNT ON; 
    declare @sql nvarchar(100) 
    set @sql=N'insert into '+@table+' ( bloggerID1, bloggerID2, weight ) values (''' 
          +ltrim(@bloggerID1)+''','''+ltrim(@bloggerID2)+''','''+ltrim(@weight)+''')' 
exec sp_executesql @sql 

解决方案 »

  1.   

    ALTER PROCEDURE [dbo].[p_BloggerGraph_Insert_NO] 
    -- Add the parameters for the stored procedure here 
    @table nvarchar(40), 
            @bloggerID1 int, 
            @bloggerID2 int, 
            @weight float 
    AS 
        declare @sql nvarchar(100) 
        set @sql=N'insert into '+@table+' ( bloggerID1, bloggerID2, weight ) values (''' 
              +cast(@bloggerID1 as varchar)+''','''+cast(@bloggerID2 as varchar)+''','''+cast(@weight as varchar)+''')' 
    --cast(@weight as varchar) 
    BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON;     -- Insert statements for procedure here 
    exec sp_executesql @sql 
    END 
      

  2.   

    1.cast(@weight as varchar) 
    2.STR(@weight,i,j)
    --i:@weight总位数
    --j:@weight四舍五入后要保留的字符串长度