In below dynamic sql I am trying to check whether temporary table (#Table) already exists if not then create using some other table.
But my problem is that irrespective what is the value in IF condtion, I am always getting error for select statement which is inside If condition
There is already an object named '#Table' in the database.
Below is the sql code.
declare @sqlstring varchar(max)
set @sqlstring=N'
select * into #Table from mst_country
if(object_id(''tempdb..#Table'') is null)
begin
select * into #Table from mst_country_bkp
end'
exec(@sqlstring)
Can any one please let us know why it can be happening?