0

我的应用程序根据我的用例要求调用存储过程。存储过程将记录插入到由主键和外键约束相关的两个表中。

这意味着表中必须存在于PatientNumber表中。VisitPatient

当我调试此过程时,设置初始值后不显示任何值。

我是新手,请帮忙。

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[Add_Patient_Visit]
AS
BEGIN TRANSACTION
    SET NOCOUNT ON; 

    declare @Visit_Number Varchar(50)
    declare @Prescription_Number Varchar(50)
    declare @Visit_Date Datetime = GETDate()

    set @Visit_Number = '25684956555'
    set @Visit_Date = GETDATE()
    set @Prescription_Number = '653214658'

    INSERT INTO Visits(Visit_Number, Visit_Date, Patient_Number)
    VALUES(@Visit_Number, @Visit_Date, @Patient_Number)

    IF @@ERROR <> 0
    BEGIN 
        ROLLBACK
        RETURN
    END

    declare @Patient_Number Varchar(50)
    declare @FirstName Varchar(50)
    declare @LastName Varchar(50)
    declare @Trible Varchar(50)
    declare @Gender Varchar(5)
    declare @Date_Of_Birth Datetime

    INSERT INTO Patient(Patient_Number, FirstName, LastName, Tribe, Gender, Date_Of_Birth)
    VALUES (@Patient_Number, @FirstName, @LastName, @Trible, @Gender, @Date_Of_Birth)

   IF @@ERROR <> 0
   BEGIN
       ROLLBACK
       RETURN
   END

   COMMIT
GO
4

1 回答 1

1

上述程序有误。您在声明之前使用@Patient_Number,同时插入表“访问”。在开始时声明它,例如:

declare @Patient_Number Varchar(50)
declare @Visit_Number Varchar(50)
declare @Prescription_Number Varchar(50)
declare @Visit_Date Datetime = GETDate()
set @Visit_Number = '25684956555'
set @Visit_Date=GETDATE()
set @Prescription_Number='653214658'

Insert into Visits(Visit_Number,Visit_Date,Patient_Number)
Values(@Visit_Number,@Visit_Date,@Patient_Number)
IF @@ERROR <> 0
BEGIN 
ROLLBACK
RETURN
END


declare @FirstName Varchar(50)
declare @LastName Varchar(50)
declare @Trible Varchar(50)
declare @Gender Varchar(5)
declare @Date_Of_Birth Datetime



INSERT INTO Patient(Patient_Number,FirstName,LastName,Tribe,Gender,Date_Of_Birth)
VALUES (@Patient_Number,@FirstName,@LastName,@Trible,@Gender,@Date_Of_Birth)
IF @@ERROR <> 0
BEGIN
ROLLBACK
RETURN

END
COMMIT
于 2013-01-30T11:45:25.047 回答