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 this
create procedure usp_GetStudents @studentId int = null
as
if (@studentId = null)
select * from Student
else
select * from Student where studentId = @studentId
Output
exec usp_GetStudents -- No records returned though there are records in the table
exec usp_GetStudents @studentId = null -- No records returned
exec usp_GetStudents @studentId = 256 -- 1 entry returned
Just curious to know if anything is wrong in the syntax/logic for returning all the entries of the table?
Thank you
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…