2012-10-10 44 views
0

我已经编写了一个存储过程并且具有一个varchar(200)varibale作为返回变量,但在输出中其显示为“将varchar值转换为整数时转换失败”程序即时没有转换为int,但即时通讯面对错误存储过程的返回值中的错误

alter proc rulename @mfid varchar(20) 
as 
declare @ACF2 varchar(200) 
begin 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where  [email protected]) > 0) 
begin 
set @ACF2='Apollo' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + 'GP' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'Tactical Comp' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'Unit Valuation' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'NPVS' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'Apollo Test' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'GP Test' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'Tactical Comp Test' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'Unit Valuation Test' 
end 
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where [email protected]) > 0) 
begin 
set @ACF2= @ACF2 + ',' + 'NPVS Test' 
end 
return @ACF2 
end 

回答

6

一个stored procedure is an integer的返回值。您应该使用output parameter instead

create procedure rulename 
    @mfid varchar(20), 
    @ACF2 varchar(200) output 
as 

-- Initialise param to empty string 
set @ACF2 = '' 

begin 
    if ... 
    begin 
     set @ACF2 = @ACF2 + '...' 
    end 
    . 
    . 
    . 
end