Can be solved using DECLARE and derived column
DECLARE @OrdNum varchar(5)
DECLARE @Empid int
SELECT * FROM (SELECT OrdNum,Empid,Mgrid,MgrLevel FROM #Orders
WHERE OrdNum=@OrdNum AND Empid=@Empid
) AS A
Heh... funny enough, that works for the data given. The given data isn't actually hierarchical data (yet).
You don't need the outer SELECT, though.
is pronounced ree-bar and is a Modenism for R
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair
How to post code problemsHow to post performance problemsForum FAQs