declare @fieldname2 varchar(200)
declare @sqls nvarchar(4000) 
declare @int2 int
set @int2=369029
  select  @fieldname2=ffieldname
from t_FieldDescription where ftableid=1400004 and fdescription='工令号'   set @sqls=' select '+ @fieldname2 + 'from iCMrpResult where finterid ='+ @int +' 
exec(@sqls)
只要加上后面的where条件语句就报错
where finterid='+@int+'应该怎样写,为什么运行报错啊?谢
ސސސ

解决方案 »

  1.   

    set @sqls=' select '+ @fieldname2 + 'from iCMrpResult where finterid ='+ @int
    exec(@sqls)
      

  2.   

    首先,你没定义@int,只定义了@int2
    其次,把@int改成CAST(@INT AS VARCHAR(10))
      

  3.   

    第三,语句改成set @sqls=' select '+ @fieldname2 + 'from iCMrpResult where finterid ='''+ @int +''''  
      

  4.   


    where finterid='+@int+'
    后面多了一个+'号~
      

  5.   

    谢谢guguda2008兄,谢谢各位兄弟