我正在使用存储过程,我正在尝试将以下信息添加到表中:
Last Name: Beesley
First Name: Pam
Hire Date: Current Date
Birth Date: 12/30/1972
Title: Receptionist
这就是我所拥有的:
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;
并且返回不起作用,因为我没有声明返回。我的问题是,如果我只是插入行或者我应该使用返回,我该怎么做才能完成这项工作?
答案 0 :(得分:5)
这样做:
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';
您不需要返回值,所有内容都将正确插入