Results 1 to 4 of 4

Thread: why this sp dont work

  1. #1
    Join Date
    Jun 2009
    Posts
    3

    why this sp dont work

    create proc parentesco2
    @a char(1),
    @b char (1)

    as
    begin
    declare @pa char(1)
    declare @pb char(1)
    declare @res varchar (50)
    declare @res2 varchar(50)
    select @pa=sujeto from persona where sujeto =@a
    select @pb=sujeto from persona where sujeto =@b
    set @res=
    case
    when @pa = @b then 'es hijo de'
    when @pb = @a then 'es padre de'
    when @pa = @pb then 'es hermano de'
    else 'otro'
    end
    If @res is Null
    If @pa is Null and @pb is Null
    Set @res = 'otro'
    Else
    Begin
    If @pa is Not Null
    Set @Res = (@pa, @b)
    If @pb is Not Null
    Set @Res2 = @a, @pb
    If @Res <> 'otro'
    Set @res = Case @res When 'hermano' Then 'sobrino' Else 'nieto'
    End
    Else if @Res2 <> 'otro'
    Set @res = Case @res2 When 'hermano' Then 'tio' Else 'abuelo'
    end

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    In which rdbms? Got any error?

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    What are you trying to achieve? You are selecting from persona table but there is no loop/cursor processesing so the whole thing will run once for the last record on the table.

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    1. you need the following statement at the end of the proc

    select isnull(@res,0) as result

    b. Always have "Begin" and "end" for IF statements

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •