当前位置: 代码迷 >> Sql Server >> 动态存储过程的,执行异常
  详细解决方案

动态存储过程的,执行异常

热度:36   发布时间:2016-04-27 15:05:47.0
动态存储过程的,执行错误
报如下错误。
将 varchar 值 ' 
select ' 转换为数据类型为 int 的列时发生语法错误。
代码如下:
create procedure roomcount
@rtype varchar(20),
@count int output
as
declare @cc int,@aa varchar(200),@Bookin int
select @Bookin=ISNULL(sum(bo_amount),'0')
from Bookin
where [email protected]
set @aa='
select [email protected]+'=isnull(count(*),0) from Rooms
where R_id='''+ @rtype + '''and r_no not in
(
select rooms.r_no
from cusroom ,rooms
where cusroom.r_no=rooms.r_no and state=1
union
select rooms.r_no
from SBookroom,rooms
where SBookroom.r_no=rooms.r_no and state=1)'
exec(@aa)
set @[email protected](@Bookin as int)
go

------解决方案--------------------
SQL code
create procedure roomcount @rtype varchar(20), @count int output as declare @cc int,@aa Nvarchar(2000),@Bookin int --改nvarcharselect @Bookin=sum(bo_amount)            --改from Bookin where [email protected] set @aa='  select @cc=isnull(count(*),0) from Rooms         --改@@cwhere R_id='''+ @rtype + '''and r_no not in ( select rooms.r_no  from cusroom ,rooms  where cusroom.r_no=rooms.r_no and state=1 union select rooms.r_no from SBookroom,rooms  where SBookroom.r_no=rooms.r_no and state=1)' exec sp_executesql @aa,[email protected] int output',@cc output    --改set @[email protected](isnull(@Bookin,0))         --改
  相关解决方案