调试存储过程但没有返回值

时间:2013-01-30 11:00:37

标签: sql-server-2008 stored-procedures

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

这意味着PatientNumber表中的Visit必须存在于Patient表中。

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

我是新手,请帮忙。

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

1 个答案:

答案 0 :(得分:1)

上述程序有误。您在声明之前使用@Patient_Number,同时在表'Visits'中插入。在开头宣布它,如:

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