我想创建一个更新表格的程序但我收到此错误:
(68,1):SQL72014:.Net SqlClient数据提供者:
消息137,级别16,状态1,过程updatePatient,行11 必须声明标量变量" @pPatient"。
以下是我要创建的程序:
CREATE PROCEDURE [dbo].[updatePatient]
@pPatient PatientTableType readonly
AS
BEGIN
UPDATE Patient
SET Patient.Cel = @pPatient.Cel,
Patient.Address = @pPatient.Address,
Patient.NamePatient = @pPatient.NamePatient,
Patient.Phone = @pPatient.Phone
WHERE Patient.idPatient = @pPatient.idPatient
END
这是我创建的类型:
CREATE TYPE [dbo].[PatientTableType] AS TABLE
(
[idPatient] SMALLINT NOT NULL,
[NamePatient] VARCHAR(250) NOT NULL,
[Cellular] INT NULL,
[Phone] INT NULL,
[Address] VARCHAR(250) NULL
);
以下是我要更新的表格:
CREATE TABLE [dbo].[Patient]
(
[idPatient] SMALLINT NOT NULL,
[NamePatient] VARCHAR(250) NOT NULL,
[Cel] INT NULL,
[Phone] INT NULL,
[Address] VARCHAR(250) NULL,
PRIMARY KEY CLUSTERED ([idPatient] ASC)
);
我做错了什么?我该如何解决?
提前致谢!
答案 0 :(得分:0)
希望这有效
CREATE PROCEDURE [dbo].[updatePatient]
(
@pPatient PatientTableType READONLY
)
AS
BEGIN
IF EXISTS(SELECT 1 FROM @pPatient)
Begin
UPDATE Patient
SET Patient.Cel = p.Cellular,
Patient.Address = p.Address,
Patient.NamePatient = p.NamePatient,
Patient.Phone = p.Phone
FROM @pPatient p
WHERE Patient.idPatient = p.idPatient
END
END
使用样本数据执行
DECLARE @PatientTableType AS PatientTableType
INSERT INTO @PatientTableType
SELECT 1,'ABC',985565,4242,'Hankong'
EXECUTE [updatePatient] @PatientTableType
SELECT * FROM [Patient]