Re: Select into problem



On Jan 30, 3:24 pm, tijgertje <griet.schauw...@xxxxxxxxx> wrote:
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.


Do you rename or drop the #t table explicitly within the proc ? . You
might want to have a look at section
"Creating a table with a variable number of columns" under Rob's
site, there is stored proc written for the same purpose

http://www.sypron.nl/dynsql.html

-HTH
Manish Negandhi
[TeamSybase Intern]
.



Relevant Pages

  • Select into problem
    ... I have created a procedure that contains dynamic sql, ... their data types. ... The first time I launch the procedure it gives correct results. ...
    (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)