set @Sqlquery='select' + @RowCount+'=count(*) from '+@From+' where '+@WhereStr
   exec sp_executesql @Sqlquery,N'@RowCount int output',@RowCount output
   set @Sqlquery='select * from ('+
   'select, 
   a.BOEPCode, 
   a.ProjectName,
    a.CustomerName,
     k.OSID AS OSCode, 
     k.ISID AS ISCOde, 
     k.TradeManagerID, 
     e.SalesTypeName,
在数据库里编译通过,一运行就报类型转换错误,麻烦各位帮忙看看是存储过程写的有问题吗?

解决方案 »

  1.   

    看看你字段中是否有不能被转为int的内容,比如空或非数字字符
      

  2.   

     set @Sqlquery='select' + @RowCount+'=count(*) from '+@From+' where '+@WhereStr
    print @Sqlquery 
      exec sp_executesql @Sqlquery,N'@RowCount int output',@RowCount output打印一下,看看语句对不对,我觉得'select' + @RowCount+'=count(*) from ‘ 这块不太对头。
      

  3.   

    set @Sqlquery='select' + CAST(@RowCount,VARCHAR(4)) +'=count(*) from '+@From+' where '+@WhereStr
    -----------
    类似上面,你得先转换一下类型,才能相应拼接
      

  4.   


    declare @ii int
    declare @str varchar(3333)
    set @ii =10
    set @str='SELECT TOP ' + cast(@ii as varchar(4)) +'  FROM [HsCode_G].[dbo].[Users]'
    print @str
    上面说法写得有点错了.
      

  5.   

    那您看这样写对吗: set @Sqlquery='select @RowCount=count(*) from '+@From+' where '+@WhereStr