解决方案 »

  1.   

    @hotellevel 是int型set @strwhere = @strwhere + ' and h.HotelStarRate='+@hotellevel;
    改爲set @strwhere = @strwhere + ' and h.HotelStarRate='+convert(varchar(20),@hotellevel);
    試試看
      

  2.   

    把你的这句话:set @strwhere = @strwhere + ' and h.HotelStarRate='+@hotellevel
    变成这样:set @strwhere = @strwhere + ' and h.HotelStarRate='+cast(@hotellevel as nvarchar)
      

  3.   


    if exists (select name from sysobjects 
             where name = 'sp_hotelquery' and type = 'p')
       drop procedure sp_hotelquery
       
    gocreate proc sp_hotelquery
    (
      @hotelcityid int,
      @hotelname nvarchar(100),
      @pagenumber int,
      @pagesize int,
      @hotellevel int,
      @totalcount int out,
      @orderbyfield nvarchar(50),
      @ordertype int)
    as
    declare @startindex int;
    declare @endindex int;
    declare @selectsql nvarchar(4000);
    declare @sqlcount nvarchar(4000);
    declare @ordertypename nvarchar(10);
    declare @strwhere nvarchar(4000);set @startindex=(@pagenumber-1)*@pagesize+1;
    set @endindex=@pagenumber*@pagesize;
     
    select @hotelcityid as hotelcityid,
           @hotelname as hotelname,
           @pagenumber as pagenumber,
           @pagesize as pagesize,
           @hotellevel as hotellevel,
           @orderbyfield as orderbyfield,
           @ordertype as ordertype,
           @startindex as startindex,
           @endindex as endindex;
     
    set @strwhere = N' where 1=1 ';if(@hotelname is not null)
    begin
     set @strwhere = @strwhere + N' and h.HotelName='''+@hotelname+N'''';
    end
     
    if(@hotellevel>0)
    BEGIN
     set @strwhere = @strwhere + N' and h.HotelStarRate='+rtrim(@hotellevel);
    ENDset @sqlcount=N'select @totalcount=count(h.HotelId) from CtripHotelInfo h inner join CtripHotelPrice p on p.HotelID = h.HotelID';
    set @sqlcount=@sqlcount+@strwhere;
    exec sp_executesql @sqlcount,N'@totalcount int out',@totalcount out;
    print @sqlcount;
      

  4.   

    set @strwhere = @strwhere + ' and h.HotelStarRate='+cast(@hotellevel as varchar(100))
      

  5.   

    报错信息已经说明了问题。
    你尝试将一个nvarchar的字符串与一个int值相加,系统强制进行隐式转换,在将nvarchar转换为int时失败。
    出错的语句是 @strwhere = @strwhere   ' and h.HotelStarRate=' @hotellevel
    你应该使用显式转换,把int转换为nvarchar,然后与其它字符串相加。