June 15, 2016 at 5:53 am
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?
June 15, 2016 at 6:03 am
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.
---------------------------------------------------------------------
June 15, 2016 at 6:06 am
great. it works perfectly fine. thank you very much. 🙂
June 15, 2016 at 6:56 am
george sibbald (6/15/2016)
put an exec in front of dbo.report_stale_open_teller_countThis 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.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply