Hi,
create procedure testemp(@empid int)
as
begin
declare @temp int;
create table #temp (mgrid int,);
select @temp=mgrid from empmgr where empid =@empid;
insert into #temp (mgrid) values (@temp);
while (@temp != @empid)
begin
select @temp=mgrid , @empid =empid from empmgr where empid =@temp;
insert into #temp (mgrid) values (@temp);
end
select * from #temp;
end
CREATE TABLE [dbo].[empmgr](
[empid] [int] NULL,
[mgrid] [int] NULL
) ON [PRIMARY]