首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

帮忙瞥个存储过程

2012-08-15 
帮忙看个存储过程if exists(select *fromsysobjects where namegetcompanymap)drop proc getcompanymap

帮忙看个存储过程
if exists(select *from sysobjects where name='getcompanymap')
drop proc getcompanymap
go
create proc getcompanymap
@areaid int,
@CustTradePtr int,
@CustTrade1 int,
@CustTrade2 int
as
declare @sql varchar(2000)
set @sql='select custname,url,didu,mobile,addr from company where 1=1'
if @CustTradePtr<>0
set @sql=@sql+' and CustTradePtr='+@CustTradePtr
if @CustTrade1<>0
set @sql=@sql+' and CustTrade1='+@CustTrade1
if @CustTrade2<>0
set @sql=@sql+' and CustTrade2='+@CustTrade2
set @sql=@sql+' and areaid='+@areaid
print(@sql)

exec getcompanymap 2342,15,0,0

在将 varchar 值 'select custname,url,didu,mobile,addr from company where 1=1 and CustTradePtr=' 转换成数据类型 int 时失败。


[解决办法]

SQL code
if exists(select *from sysobjects where name='getcompanymap')drop proc getcompanymapgocreate proc getcompanymap@areaid int,@CustTradePtr int,@CustTrade1 int,@CustTrade2 intasdeclare @sql varchar(2000)set @sql='select custname,url,didu,mobile,addr from company where 1=1'if @CustTradePtr<>0set @sql=@sql+' and CustTradePtr='+convert(varchar(20),@CustTradePtr)if @CustTrade1<>0set @sql=@sql+' and CustTrade1='+convert(varchar(20),@CustTrade1)if @CustTrade2<>0set @sql=@sql+' and CustTrade2='+convert(varchar(20),@CustTrade2)set @sql=@sql+' and areaid='+convert(varchar(20),@areaid)print @sql
[解决办法]
exec (@sql),加括号

[解决办法]
你的存储过程中,exec @sql改写成execute (@sql),加括号
探讨
我是这样写的

SQL code


if exists(select *from sysobjects where name='getcompanymap')
drop proc getcompanymap
go
create proc getcompanymap
@areaid int,
@CustTradePtr int,
@CustTrade1 int,
@Cus……

[解决办法]
declare @sql varchar(2000) 
@sql是字符串,参数是int,不能直接 “+”哈,用convert转换一下就好了

热点排行