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      MFID=@mfid) > 0)
begin
set @ACF2='Apollo'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + 'GP'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'Tactical Comp'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'Unit Valuation'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'NPVS'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'Apollo Test'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'GP Test'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'Tactical Comp Test'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'Unit Valuation Test'
end
if((select count(distinct(Rulename)) as count1 from MainframeExtractsPLP where MFID=@mfid) > 0)
begin
set @ACF2= @ACF2 + ',' + 'NPVS Test'
end
return @ACF2
end
4

1 に答える 1

6

ストアド プロシージャの戻り値は整数です。代わりに出力パラメータを使用してください。

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
于 2012-10-10T06:20:38.257 に答える