Create dinamic table - newbie question

  • Help urgent please, I've a piece of code that needs to alter or create a table dinamic, at the end I need to "run" the @stfield.

    Thanks in advance

    RM

    Create procedure P1

    as

    declare

    @cont int,

    @stfield varchar(255)

    begin

     create table t1

     (c1 int null)

     select @cont = 0

     while @cont <5

      begin

       select @stfield = "alter table t1 add C"+convert(varchar, @contador) + " int null"

       select @stfield

       select @cont = @cont +1

      end

     select * from t1

     drop table t1

    end

    go

  • just for the record, I'm runnig on 6.5

     

    tkx

  • you should be able to

    exec (@stfield)

    after while/end.

     

    regards,

    Chris

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply