I have a Stored Procedure which returns data based on the StatusId.
DECLARE @StatusId INT=2
SELECT * FROM Employees
If the StatusId is null,then it returns all the rows from the table Employees.
And if StatusId is passed,the query returns data based on the StatusId.
When @StatusId is passed as NULL,does the above query work as self-join?
Also,comparing the above query with the one mentioned below,which query is more appropriate(best practice).
When,I compared the query plan,both output are same.
SELECT * FROM Employees e
WHEN @StatusId IS NULL THEN 1
WHEN @StatusId=e.StatusId THEN 1