从存储过程返回自定义值

时间:2011-05-09 05:41:37

标签: sql-server stored-procedures

我有这个商店程序;

USE [DataBase]
GO
/****** Object:  StoredProcedure [dbo].[DeleteAll]    Script Date: 05/09/2011 00:18:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[DeleteAll]
    @theID uniqueidentifier
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON
    BEGIN TRANSACTION

    BEGIN TRY

        DELETE FROM Table1
        WHERE ID = @theID    

        DELETE FROM Table2
        WHERE ID = @theID    

        DELETE FROM Table3
        WHERE ID = @theID

    END TRY

    BEGIN CATCH
        IF @@TRANCOUNT > 0 
            BEGIN 
                ROLLBACK TRANSACTION
            END
    END CATCH;

    IF @@TRANCOUNT > 0 
        BEGIN
            COMMIT TRANSACTION
        END
END

可以根据结果返回一个整数??

例如:1表示成功,2表示捕获。

提前致谢!

埃德加。

1 个答案:

答案 0 :(得分:0)

是的,这是可能的。

使用RETURN语句并检查返回值in your client code

CREATE PROCEDURE checkstate @param varchar(11)
AS
IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE BusinessEntityID = @param) = 'WA'
    RETURN 1
ELSE
    RETURN 2;
GO