I am getting this error:
Procedure or function ‘NewEmployee’ expects parameter ‘@LastName’, which was not supplied
This is what I have:
CREATE PROCEDURE NewEmployee1 (
@LastName nvarchar(75)
,@FirstName nvarchar(50)
,@HireDate datetime
,@Birthdate datetime
,@Title nvarchar(30))
WITH EXECUTE AS CALLER
AS
BEGIN
Set NOCOUNT ON;
Begin Try
Begin Transaction;
INSERT INTO Employees (LastName,FirstName,HireDate,BirthDate,Title)
VALUES (@LastName, @FirstName, @HireDate,@Birthdate,@Title)
COMMIT TRANSACTION;
End Try
Begin Catch
--Rollback any active or uncommitable transactions before
--inserting information in the errorLog
If @@Trancount > 0
Begin
Rollback Transaction;
End
Execute NewEmployee1 ;
End Catch;
End;
Exec NewEmployee
@LastName = 'Halpert',
@FirstName = 'Jim',
@HireDate = '11/14/2011',
@BirthDate = '04/02/1971',
@Title = 'Sales';
Should I have it like @lastName nvarchar(75) = Null?
You have the line
Execute NewEmployee1 ;which attempts to execute the stored procedure with no parameters.If you want default values assigned to parameters, you need to do as you suggested…
Or replacing the NULLs with any appropriate default value.