drop table #temp declare @tablename varchar(10) create table #temp (ch char(1)) set @tablename = '#temp' if object_Id(@tablename) is not null exec ('drop table ' + @tablename)And it didn't work. Give me one sec, I think you need a variable for whole EXEC line.
>CREATE PROCEDURE spDropTable > @sTableName VARCHAR(MAX) > >AS > > IF OBJECT_ID(@sTableName) IS NOT NULL > EXEC('DROP TABLE ' + @sTableName) >>
> >EXEC spDropTable '#TmpNetAmt' > >SELECT t.iTrade_Id > INTO #TmpNetAmt > FROM Trade t >>
declare @tablename varchar(10) >> >>create table #temp (ch char(1)) >>set @tablename = '#temp' >>if object_Id(@tablename) is not null >> drop table #temp>>
>>>DECLARE @sTableName VARCHAR(MAX) >>> >>>if object_ID('N''#Stats') is not null >>> drop table #Stats>>>
>>>>if object_ID('N''#Stats') is not null >>>> drop table #Stats>>>>
>>>>if exists (....) >>>> set @myRetValue = 1>>>>
>>>>>CREATE FUNCTION dbo.fnTableExists >>>>> (@sTableName VARCHAR(50)) >>>>> >>>>>RETURNS TinyInt >>>>>AS >>>>> >>>>> BEGIN >>>>> >>>>> DECLARE @bTableExists TINYINT >>>>> SET @bTableExists = 0 >>>>> >>>>> SELECT @bTableExists = 1 >>>>> WHERE EXISTS >>>>> (SELECT Table_Name >>>>> FROM INFORMATION_SCHEMA.TABLES >>>>> WHERE LOWER(Table_Name) = LOWER(@sTableName)) >>>>> >>>>> RETURN @bTableExists >>>>> >>>>> END >>>>> >>>>>>>>>>
>>>>> >>>>>SELECT t.iTrade_Id, t.decTrade_Ext_Price + t.decTrade_Shipping_Charge + t.decTrade_Other_Charge AS NetAmount >>>>> INTO #TmpNetAmt >>>>> FROM Trade t >>>>> >>>>>DECLARE @bTableExists TINYINT >>>>>SELECT @bTableExists = dbo.fnTableExists('#TmpNetAmt') >>>>> >>>>>SELECT @bTableExists -- Returns 0 >>>>>>>>>>