解决方案 »
- 处理这个问题有没有简单方法
- sql 文件组理解问题
- 我想把一个表的一个列字段改长一点。如何用SQL语句更改啊?
- 这个SQL语句怎么写(列转行)
- sql2005 企业版在安装目录下的log文件夹下总是产生SQLDump*.txt SQLDump*.log SQLDump*.mdmp文件。
- SQL2000游标的问题
- 为什么在sql server2005右键查看数据库属性就出错
- 第一次来这里,我们下学期学SQL,我还一点都不懂,请教一下,还请介绍几本好书
- JSP调用“存储过程”出错,但是用“查询分析器”执行是正确的。
- 急!帮帮我-写存储过程存入远程数据库表中
- 1000w以上的数据sqlserver存储方案
- 关于数据库的。求大神指导
改爲set @strwhere = @strwhere + ' and h.HotelStarRate='+convert(varchar(20),@hotellevel);
試試看
变成这样:set @strwhere = @strwhere + ' and h.HotelStarRate='+cast(@hotellevel as nvarchar)
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;
你尝试将一个nvarchar的字符串与一个int值相加,系统强制进行隐式转换,在将nvarchar转换为int时失败。
出错的语句是 @strwhere = @strwhere ' and h.HotelStarRate=' @hotellevel
你应该使用显式转换,把int转换为nvarchar,然后与其它字符串相加。