alter proc GetRes
@id int
as
declare @sql varchar(1000)
set @sql='select * from CalcResults where ResultID='+@id;----------这个参数怎么传。
begin
exec(@sql)
endexec GetRes 10执行时报
Msg 245, Level 16, State 1, Procedure GetRes, Line 5
在将 varchar 值 'select * from CalcResults where ResultID=' 转换成数据类型 int 时失败。

解决方案 »

  1.   

    set @sql='select * from CalcResults where ResultID='''+ltrim(@id)+'''';
      

  2.   

    呵呵。楼上的谢谢你。我知道了。
    set @sql='select * from CalcResults where ResultID='+Convert(varchar(10),@id);
      

  3.   

    alter proc GetRes 
    @id int 
    as 
    declare @sql varchar(1000) 
    set @sql='select * from CalcResults where ResultID='''+ltrim(@id)+''''----------这个参数怎么传。 
    begin 
    exec(@sql) 
    end exec GetRes 10
      

  4.   

    楼主记住 
    使用动态时候 是用字符串拼接的 
    因为你的@id 为INT类型 所以要转化为 字符型才可以
      

  5.   


    -- TRY Thisalter proc GetRes 
    @id int 
    as 
    declare @sql varchar(1000) 
    set @sql='(select * from CalcResults where ResultID='+@id+')';   ----------这个参数怎么传。 begin 
    exec(@sql) 
    end exec GetRes 10