-- create a table CREATE TABLE employee ( EmployeeID int NULL, EmployeeName nvarchar(50) NULL, ManagerID int NULL, DepartmentID int NULL, Salary float NULL); INSERT INTO employee VALUES (100, "ANURAG", 101, 100, 200.25); INSERT INTO employee VALUES (101, "harsh", 102, 444, 100.47); INSERT INTO employee VALUES (102, "SUMIT",104 , 444, 103.22); INSERT INTO employee VALUES (103, "RUHI",104 , 444, 102.14); INSERT INTO employee VALUES (104, "KAE",111 , 555, 103.14); INSERT INTO employee VALUES (105, "SHIR",NULL , 555, 111.14); select * from employee; /*Please write a T-SQL query to display every employee along with his manager.*/ Select emp.EmployeeName as employee_name , mag.EmployeeName as manager_name From employee as emp, employee as mag Where emp.ManagerID = mag.EmployeeID ; /*Please write a T-SQL query to display all the employees that their manager is not working in the same department as them, - An employee that does not have a manager should also be listed.*/ Select emp.EmployeeID, emp.EmployeeName, emp.ManagerID, emp.DepartmentID ,emp.Salary From employee as emp, employee as mag Where emp.DepartmentID != mag.DepartmentID and emp.ManagerID =mag.EmployeeID union Select emp.EmployeeID, emp.EmployeeName, emp.ManagerID, emp.DepartmentID ,emp.Salary From employee as emp Where emp.ManagerID IS NULL; -- fetch some values
To embed this project on your website, copy the following code and paste it into your website's HTML: