I have tried this:
if object_id('a_proc22') is not null
CREATE PROCEDURE a_proc22 AS SELECT 1
go
but it gives me a syntax error.
But this seemed to compile:
if object_id('a_proc22') is not null
EXEC('CREATE PROCEDURE a_proc22 AS SELECT 1')
go
Why is the first one incorrect?