S'il vous plaît prendre en considération:SQL 2005 - Temp Table d'émission
declare @abbrev varchar(20); set @abbrev='';
select pk_term into #t2 from #t1 where pk_term in (select distinct(fk_term) from tblabbreviations where abbreviation like @abbrev)
select @count=count(*) from #t2
print 'count t2='+convert(varchar(10),@count)
On suppose # t1 contient 10 lignes. Je veux que # t2 contienne 10 lignes quand @abbrev est '', ou 10 lignes ou moins (typiquement moins) quand say @ abbrev = 'av%'.
J'ai essayé ceci:
declare @abbrev varchar(20); set @abbrev='';
if @abbrev <> ''
begin
select pk_term into #t2 from #t1 where pk_term in (select distinct(fk_term) from tblabbreviations where abbreviation like @abbrev)
select @count=count(*) from #t2 -- should be same as t1
print 'count t2='+convert(varchar(10),@count)
end
else
select pk_term into #t2 from (select pk_term = null) -- ensure #t2 is created regardless
mais bien sûr, je reçois l'erreur « Il existe déjà un objet nommé « t2 # » dans la base de données. »
Comment contourner ce problème?
Merci beaucoup à l'avance.
Mfg, Mark
Merci Will. Tellement évident! J'avais un moment de brouillard de cerveau :) – Mark