0

I'm trying to run this sp but... I cannot figure out where is the mistake. can you help me?

alter procedure prova @condizione=1, @parametro=39
    @condizione1 int,
    @parametro int
as

begin
declare @condizione int
set @condizione = @condizione1


    SET NOCOUNT ON
select  pf.CostumerCode, pf.BelongTo
from    tbprodfin pf
    where 
    CASE @condizione
        WHEN 1 THEN pf.IdPF
        WHEN 2 THEN pf.BelongTo
    END  = @parametro

end

3 Answers3

0

Given the little information provided: i suppose to change your select clause to sth. like

select  pf.CostumerCode, pf.BelongTo
from    tbprodfin pf
where 1 = 1
    and (   (@condizione = 1 and @parametro = pf.IdPF)
        or  (@condizione = 2 and @parametro = pf.BelongTo))

This might not work initially but it should get you startet as i hope. Also, see this related question.

Community
  • 1
  • 1
nozzleman
  • 9,529
  • 4
  • 37
  • 58
0

try it like that

  CREATE procedure prova @condizione int =1,
 @parametro int =39,
    @condizione1 int    --what for??
as
begin
SET NOCOUNT ON
if @condizione=1
begin
select  pf.CostumerCode, pf.BelongTo
from    tbprodfin pf
where pf.IdPF= @parametro
end 
else 
begin
if @condizione=2
begin
select  pf.CostumerCode, pf.BelongTo
from    tbprodfin pf
where pf.BelongTo= @parametro
end  
end
end
Dudi Konfino
  • 1,126
  • 2
  • 13
  • 24
0

If i understand what are u want. There is result with use CASE ...

select  pf.CostumerCode, pf.BelongTo
from    tbprodfin pf
    where 
    (CASE WHEN @condizione = 1 THEN pf.IdPF
          WHEN @condizione = 2 THEN pf.BelongTo END) = @parametro
Matej Hlavaj
  • 900
  • 7
  • 10