title: conditional stored procedure with/without passing parameter
body: <p>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</p>
  
  <pre><code>create procedure usp_GetStudents @studentId int = null
  as
    if (@studentId = null)
      select * from Student
    else
      select * from Student where studentId = @studentId
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Just curious to know if anything is wrong in the syntax/logic for returning all the entries of the table?</p>
  
  <p>Thank you</p>