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:
01328380
Views:
9
--drop table #temp

create table #temp (ch char(1))


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

if object_id('tempdb..#temp') is not null
  begin
  print 'Try to delete'
  set @execS = 'drop table ' + @tablename
  exec sp_executesql @execS
end
This works.

And this
create table #temp (ch char(1))


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

if object_id(@tablename) is not null
  begin
  print 'Try to delete'
  set @execS = 'drop table ' + @tablename
  exec sp_executesql @execS
end
doesn't.

I don't know what's going on. Looks like it could not detect immediatelly using the name as a variable.
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