How to write a code if exist object inside a code try catch block when am trying write a code its not working.Please find below a code as per my requirement and when i am trying keep a code before if exist its not throwing error.
Create PROCEDURE dbo.error
@paramet int = 0
AS
if exists (select * from sysobjects where id = object_id('[dbo].[tmp_error_1]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
drop table dbo.error
if exists (select * from sysobjects where id = object_id('[dbo].[tmp_error_1]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
drop table dbo.error
if @paramet = 1
select column1 into dbo.error from Table1 where Id in (
select distinct Id from table1 where Active = 'N'
--Id---
delete from dbo.error where inv_ctl_nbr in (
select distinct Id from dbo.error where Id= 1)
else ------Here am getting error 'Incorrect syntax error 'else'
BEGIN TRY
exec dbo.error @paramet = 1
END TRY
BEGIN CATCH
------SET NOCOUNT ON
------exec dbo.spGetErrorInfo
Print ERROR_MESSAGE()
END CATCH
if exists (select * from sysobjects where id = object_id('[dbo].[tmp_error_1]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
drop table [dbo].[tmp_error_1]
if exists (select * from sysobjects where id = object_id('[dbo].[tmp_error_1]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
drop table [dbo].[tmp_error_1]
Go