Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Location
    Novi Sad, Serbia
    Posts
    11

    Unanswered: Column name from variable

    Hi

    I Am usin ASA 8.0.2. and in stored procerure trying to add column to table with name of column as variable.

    How can I do this?

    example:

    Declare @var_1 char(10);
    set @var_1 = 'Column_1';
    Alter table Pivot add @var_1 numeric(10,2) default 0;

  2. #2
    Join Date
    Jun 2002
    Posts
    10
    Hello,

    I'm not an ASA user, but in ASE, you could do it using the execute immediate functionality:

    example:

    Declare @var_1 char(10)
    Declare @cmd varchar(255)
    set @var_1 = 'Column_1'
    set @cmd = 'Alter table Pivot add ' + @var_1 + ' numeric(10,2) default 0'
    exec(@cmd);

    Hope that helps.

  3. #3
    Join Date
    Feb 2002
    Location
    Willy is on vacation
    Posts
    1,208
    ASA has an similar syntax

    Declare @var_1 char(10);
    set @var_1 = 'Column_1';
    EXECUTE IMMEDIATE 'Alter table Pivot add '
    || @var_1
    ||numeric(10,2) default 0;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •