CREATE PROCEDURE [dbo].[spTest]
(
@studentID int
)
AS
IF (@studentID !=null)
begin
SELECT Test.ID, Test.Name, Test.Address, Test.DepID, Test.Donation, TestRow.DepartmentName
FROM Test
INNER JOIN TestRow ON Test.DepID = TestRow.DepID
WHERE Test.ID=@studentID
end
ELSE
begin
SELECT Test.ID, Test.Name, Test.Address, Test.DepID, Test.Donation, TestRow.DepartmentName
FROM Test
INNER JOIN TestRow ON Test.DepID = TestRow.DepID
end
RETURN
GO