SQL问题求解
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE apf_InsertCustomer
(@FirstName varchar(50) =
@LastName varchar(50) = )
AS
BEGIN
SET NOCOUNT ON;
SELECT @FirstName, @LastName
END
GO
CREATE PROCEDURE CustomerDetails.apf_InsertCustomer
@FirstName varchar(50) ,
@LastName varchar(50),
@CustTitle int,
@CustInitials nvarchar(10),
@AddressId int,
@AccountNumber nvarchar(15),
@AccountTypeId int
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO CustomerDetails.Customers
(CustomerTitleId,CustomerFirstName,CustomerOtherInitials,
CustomerLastName,AddressId,AccountNumber,AccountTypeId,
ClearedBalance,UnclearedBalance)
VALUES (@CustTitle,@FirstName,@CustInitials,@LastName,
@AddressId,@AccountNumber,@AccountTypeId,0,0)
END
GO
消息 137,级别 15,状态 2,第 1 行
必须声明标量变量 "@LastName"。
[解决办法]
CREATE PROCEDURE apf_InsertCustomer
(@FirstName varchar(50) = '',--这个存储过程的参数,要么给默认值,要么把等于号去掉。且两个参数之间少了个逗号分隔
@LastName varchar(50) = '')
AS
BEGIN
SET NOCOUNT ON;
SELECT @FirstName, @LastName
END
GO
CREATE PROCEDURE CustomerDetails.apf_InsertCustomer
@FirstName varchar(50) ,
@LastName varchar(50),
@CustTitle int,
@CustInitials nvarchar(10),
@AddressId int,
@AccountNumber nvarchar(15),
@AccountTypeId int
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO CustomerDetails.Customers
(CustomerTitleId,CustomerFirstName,CustomerOtherInitials,
CustomerLastName,AddressId,AccountNumber,AccountTypeId,
ClearedBalance,UnclearedBalance)
VALUES (@CustTitle,@FirstName,@CustInitials,@LastName,
@AddressId,@AccountNumber,@AccountTypeId,0,0)
END