Select into problem



Hi,

I have a problem concerning the select into statement.
I have created a procedure that contains dynamic sql, which creates a
variable number of columns.

The sql looks like :

@sql = 'select columnA, columnB, columnC,.... into #t from.....'
execute(@sql)
select * from #t

#t is nowhere defined as I cannot predict the number of columns nor
their data types.

The first time I launch the procedure it gives correct results.
However if i launch the procedure again with different arguments
( creating more, or less columns with different column names ) the
definition of #t does not change.

It seems that when the procedure ends it does not free up #t

Thanks in advance for some suggestions!
Griet
.



Relevant Pages

  • Re: Select into problem
    ... I have created a procedure that contains dynamic sql, ... The first time I launch the procedure it gives correct results. ... Do you rename or drop the #t table explicitly within the proc? ...
    (comp.databases.sybase)
  • Re: Help Needed - ISNULL when the field is already null..
    ... I sure won't go into dynamic sql, ... écrit dans le message de news:Ozl8y$dFFHA.3732@TK2MSFTNGP14.phx.gbl... ... for the first time I have to do this on fields that ... >> of course, WHERE Field IS NULL works like a charm, but I need this to be ...
    (microsoft.public.sqlserver.programming)
  • Re: CRUD in SP or Dynamic SQL
    ... parsed and complied once (the first time it is executed). ... Dynamic SQL requires parsing and compiling on *every* execution. ... Also from a maintenance perspective - when you use stored procedures - you ...
    (microsoft.public.dotnet.framework.aspnet)