incorrect syntax

  • I am new to SQL & I wonder if anybody can help me with this issue.

    I am trying to run the following query but it keeps on failing with the Msg 102, Level 15, State 1, Line 12

    Incorrect syntax near 'dbo'.

    DECLARE @Role NVARCHAR(120);

    SELECT @Role = ars.role_desc

    FROM sys.availability_replicas ar

    JOIN sys.dm_hadr_availability_replica_states ars ON ar.replica_id = ars.replica_id

    JOIN sys.availability_groups ag ON ars.group_id = ag.group_id

    WHERE ag.name = 'ETHIXAG1'

    AND ars.is_local = 1;

    IF @Role = 'PRIMARY'

    BEGIN;

    dbo.report_stale_open_teller_count

    END;

    But if I run “dbo.report_stale_open_teller_count” separately, it works fine.

    How can I make the first query run successfully?

  • put an exec in front of dbo.report_stale_open_teller_count

    This is because if the execution of a stored procedure is not the only statement in the batch, you need to add an explicit exec

    the ; after BEGIN is not necessary either.

    ---------------------------------------------------------------------

  • great. it works perfectly fine. thank you very much. 🙂

  • george sibbald (6/15/2016)


    put an exec in front of dbo.report_stale_open_teller_count

    This is because if the execution of a stored procedure is not the only statement in the batch, you need to add an explicit exec

    the ; after BEGIN is not necessary either.

    Actually, neither the BEGIN nor the END are strictly necessary, as the IF [true] condition is only a single statement.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply