Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Function To Test For Table Doesn't Work
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01328338
Message ID:
01328370
Views:
9
Sorry, can not make it to work for some reason and I need to work on a different task.
drop table #temp

create table #temp (ch char(1))
go

--if object_Id(@tablename) is not null
declare @tablename varchar(10)
declare @execS varchar(max)
set @tablename = '#temp' 

if object_id('N''#temp') is not null -- Doesn't work
  begin
  print 'Try to delete'
  set @execS = 'drop table ' + @tablename
  exec sp_executesql @execS
end
>Ok, I don't understand what's wrong here:
>
>
>This works:
>
>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)
>
>
>
>
>This does not work:
>
>DECLARE @sTableName varchar(max)
>
>SET @sTableName = '#temp'
>
>if object_Id(@sTableName) is not null
>  exec ('drop table ' + @sTableName)
>
>SELECT t.iTrade_Id
>	INTO #temp
>	FROM Trade t
>
>
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform