我创建了一个存储过程,当不传递任何参数时,它应该返回整个表。但是如果通过了 studentId,则返回她的详细信息。像这样的东西
create procedure usp_GetStudents @studentId int = null
as
if (@studentId = null)
select * from Student
else
select * from Student where studentId = @studentId
输出
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
只是想知道返回表的所有条目的语法/逻辑是否有问题?
谢谢