norris1023
norris1023

Reputation: 633

Working with stored procedure

I am working with a stored procedure and I am trying to add the following information to the table:

Last Name: Beesley
First Name: Pam
Hire Date: Current Date
Birth Date: 12/30/1972
Title: Receptionist

This is what I have:

CREATE PROCEDURE NewEmployee (
     @LastName nvarchar(75)
     ,@FirstName nvarchar(50)
     ,@HireDate datetime
     ,@Birthdate datetime
     ,@Title nvarchar(30))

AS
BEGIN
    INSERT INTO Employees (LastName,FirstName,HireDate,BirthDate,Title)
    VALUES (@LastName, @FirstName, @HireDate,@Birthdate,@Title)

End
GO

Declare @Return int;

 Exec @Return = NewEmployee
 @LastName = 'Beesley',
 @FirstName = 'Pam',
 @HireDate = 'Current Date',
 @BirthDate = '12/30/1972',
 @Title = 'Receptionist';

 Select @Return;

And the return is not working because I have not declare the return. My question is what can I do to make this work should I just insert the row or should I use the return?

Upvotes: 0

Views: 135

Answers (1)

GregM
GregM

Reputation: 2654

Do this :

CREATE PROCEDURE NewEmployee (
     @LastName nvarchar(75)
     ,@FirstName nvarchar(50)
     ,@HireDate datetime
     ,@Birthdate datetime
     ,@Title nvarchar(30))

AS
BEGIN
    INSERT INTO Employees (LastName,FirstName,HireDate,BirthDate,Title)
    VALUES (@LastName, @FirstName, @HireDate,@Birthdate,@Title)

End
GO



 Exec NewEmployee
 @LastName = 'Beesley',
 @FirstName = 'Pam',
 @HireDate = 'Current Date',  <-- EDIT : Here you need a real date 
 @BirthDate = '12/30/1972',
 @Title = 'Receptionist';

You don't need the return value and everything will be inserted correctly

Upvotes: 5

Related Questions