I created a stored procedure which when passed nothing as parameter should return the entire table. But if the studentId is passed, then return her details. Something like t
Shorter way to do that:
create procedure usp_GetStudents @studentId int = null
as
select * from Student
where studentId = isnull(@studentId,studentId)
You can't chack if value is null using =.
For your example you have to replace condition @studentId = null to is null syntax.
Try to change your code as below:
create procedure usp_GetStudents @studentId int = null
as
if (@studentId is null)
select * from Student
else
select * from Student where studentId = @studentId