Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Function To Test For Table Doesn't Work
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01328338
Message ID:
01328370
Vues:
10
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform