2012-10-10 41 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