日期:2014-05-18  浏览次数:20419 次

看看这个存储过程 哪儿有错?
declare   @return_str   nvarchar(4000)
set   @return_str= ' '
exec   pro_ziFuChuanZuHe_PaoXi   'daAn01,daAn03,daAn02,daAn04 ', ', ',@return_str=@return_str   output
--print   @return_str


--把字符串组合排序   .比如:“daAn01,daAn03,daAn02,daAn04”
create       procedure   pro_ziFuChuanZuHe_PaoXi
@str_zuHe   nvarchar(4000),--要分离的字符串组合
@jianGe   nvarchar(4000),--间隔符
@return_str   nvarchar(4000)   output
as
begin   tran

-- <1> 创建临时表
create   table   #t1(
col1   nvarchar(4000)
)
-- <2> 用分离函数,分离出来,插入到临时表

declare   @fenLi_i   int
set   @fenLi_i=0
while   @fenLi_i <len(@str_zuHe)
begin  
    set   @fenLi_i=@fenLi_i+1
    if   SUBSTRING(@str_zuHe,@fenLi_i,1)=@jianGe
          begin        
--得到阅卷人
--print   left(@str_zuHe,@fenLi_i-1)
insert   into   #t1
values(left(@str_zuHe,@fenLi_i-1))

              set   @str_zuHe=SUBSTRING(@str_zuHe,@fenLi_i+1,len(@str_zuHe))
              set   @fenLi_i=0
          end    
end
--得到最一个卷人
--print   @str_zuHe
insert   into   #t1
values(@str_zuHe)


-- <3> 用游标   访问   进行排序后的该表查询结果   ,组合成字符串

SET   @return_str= ' '


declare   @count   int
select   @count=count(col1)   from   #t1
declare   @lingShiStr   nvarchar(4000)
set   @lingShiStr= ' '
declare   yb_XuHao   cursor
scroll
for  
select   col1   from   #t1   order   by   col1   asc

open   yb_XuHao
while   @count> 0
begin
fetch   next   from   yb_XuHao   into   @lingShiStr
set   @return_str=@return_str   +   @jianGe     +   @lingShiStr
set   @count=@count-1
--print   @return_str
end


close   yb_XuHao
deallocate   yb_XuHao

drop   table   #t1

commit   tran
--print   @return_str
return   @return_str



------解决方案--------------------
你最后一句return @return_str有问题,只能返回整数,去掉后即可
------解决方案--------------------
这里不用你返回参数了,存储过程有两种方式返回值:
第一:通过output 参数
第二:通过return来实现

而在你的存储过程已经声明了一个output参数,只要你在你的存储过程已经给这个值赋值了,它就能返回回去.

建议一般用output参数,因为它可以返回多个,而return只能是一个,return一般用来返回:影响的行数,错误编码等