-
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
-
In which rdbms? Got any error?
-
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.
-
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
-
Forum Rules
|
|