我每次尝试运行我的proc时都会出现以下错误...'END'附近的语法不正确

时间:2015-10-18 15:31:21

标签: sql sql-server

class Nested(models.Model):
    user = models.OneToOneField(User)
    personalid = models.CharField(max_length=255)
    agreed_terms_of_service = models.BooleanField()
    city = models.CharField(max_length=255, blank=True, null=True)

2 个答案:

答案 0 :(得分:1)

您缺少end try / begin catch / end catch来实际处理您已启动的异常处理。

答案 1 :(得分:1)

Create PROCEDURE [dbo].[SP_StoredProc_Status] @Procname varchar(50)
AS

BEGIN
    ---- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT 
    SET NOCOUNT ON;
    SET DATEFORMAT dmy;

    BEGIN TRY
        -- Check if the procedure is already running.
        -- This check is MANDATORY in all stored procs.
        IF EXISTS (
                SELECT *
                FROM IMP_StoredProcRunTracking
                WHERE StoredProcName = @Procname
                    AND DATEADD(hh, 1, ISNULL(StartedAt, DATEADD(year, - 50, GETDATE()))) > GETDATE()
                )
            BEGIN
                RETURN
            END
        ELSE
            BEGIN
                MERGE INTO IMP_StoredProcRunTracking AS Target
                USING (
                    SELECT @procname StoredProcName
                    ) AS Source
                    ON Target.StoredProcName = Source.StoredProcName
                WHEN MATCHED
                    THEN
                        UPDATE
                        SET Target.StartedAt = GETDATE()
                WHEN NOT MATCHED
                    THEN
                        INSERT (
                            StoredProcName
                            ,StartedAt
                            )
                        VALUES (
                            @Procname
                            ,GETDATE()
                            );
                        end


    END TRY

    BEGIN CATCH
    -- Execute error retrieval routine.

    END CATCH

END