当前位置: 代码迷 >> Sql Server >> 存储过程调试时变量为空,来下
  详细解决方案

存储过程调试时变量为空,来下

热度:148   发布时间:2016-04-27 19:13:44.0
存储过程调试时变量为空,高手进来下
SQL code
ALTER proc DingDan_GetCount@VIPID varchar(50),@ShopID intasbegindeclare @where varchar(1000),@SQl varchar(1000)if(len(@VIPID)>0)set @where=' [email protected]+' and'if(@ShopID>0)set @[email protected]+' [email protected]+' and'if(len(@where)>0)Set @where=' where '+substring(@where,0,len(@where)-3)set @SQL = 'select count(*) from [email protected]exec(@SQL)[email protected]?end


------解决方案--------------------
SQL code
ALTER proc DingDan_GetCount@VIPID varchar(50),@ShopID intasbegindeclare @where varchar(1000),@SQl varchar(1000)if(len(@VIPID)>0)set @where=' and [email protected]if(@ShopID is not null)set @where=' and Shop_ID='+ltrim(@ShopID)if(len(@where)>0)set @SQL = 'select count(*) from DingDan where 1=1 [email protected]exec(@SQL)[email protected]?end
------解决方案--------------------
SQL code
ALTER proc DingDan_GetCount@VIPID varchar(50),@ShopID intasbegindeclare @where varchar(1000),@SQl varchar(1000)if(len(@VIPID)>0)set @where=' [email protected]+' and'if(@ShopID>0)set @[email protected]+' [email protected]+' and'/*[email protected][email protected][email protected]2、拼字符串时注意数据类型,@ShopId是int型。*/if(len(@where)>0)Set @where=' where '+substring(@where,0,len(@where)-3)set @SQL = 'select count(*) from [email protected]exec(@SQL)[email protected]?end
------解决方案--------------------
SQL code
--按楼主的可以这么改试试。ALTER proc DingDan_GetCount@VIPID varchar(50),@ShopID intasbegindeclare @where varchar(1000),@SQl varchar(1000)if(len(@VIPID)>0)set @where=' [email protected]+' and 'if(@ShopID>0)set @where=isnull(@where,'')+' Shop_ID='+ltrim(@ShopID)+' and'if(len(@where)>0)Set @where=' where '+substring(@where,0,len(@where)-3)set @SQL = 'select count(*) from DingDan '+isnull(@where,'')--为什么执行了这步了exec(@SQL)[email protected]?end
  相关解决方案