I'm using SQL Server 2008 R2.
I have a table that looks like this:
Here is my fiddle for it: http://sqlfiddle.com/#!3/9ad11/2
If you look at the table. The value in the BossID column contains the EmployeeID of that employee's boss.
So if you look at my table Homer, Michael, Taylor and Erin's BossID
which pertains to the EmployeeID
of value 2451
which is Montgomery Burns.
So Montgomery Burns is Homer, Michael, Taylor and Erin's Boss.
Now if you look at the BossID value of 2356 for Montgomery Burns that pertains to EmployeeID of value 2356. So Donal Trump is Montgomery Burn's boss.
What I want is to write a query that takes in one parameter called @username.
So when I feed it the username of an employee the result set is all of the people that are his employees.
So for example if I set the parameter like this SET @UserName = 'mburns' then the result set should show all the employees which work for montgomery burns. Which in the case of my table would look like this:
if I set the parameter like this SET @UserName = 'dtrump' then the result set should show all the employees which work for donald trump. Which in the case of my table would look like this:
Right now I have the following query:
DECLARE @UserName varchar(50)
SET @UserName = 'mburns'
WHERE [UserName] = @UserName
But that gives me this:
Here is the fiddle for my query: http://sqlfiddle.com/#!3//3
Any idea of how I need to revise my query?