Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    8

    Question Unanswered: Sybase create tables dynamically from values of variables ( tricky )

    Hi Frenz,
    I am trying to code something that needs dynamic generation of tables. So in the stored proc, i will query a config table and get the name of the table that needs to be created ... something like ..

    delcare @name varchar(30)
    select @name=name from config

    create table @name --> just example, this doesn't work anyway.

    so how do i achive this?
    Also i need to create that table with column names from a resultset rows.

    Select column_name, column_type from column_config
    --suppose above query returns 10 rows, then my table need to have these 10 columns..

    Let me know if you need more info. Need to resolve ASAP so please advice if you have done it in the past. Thanks a ton in advance.
    Regards.

  2. #2
    Join Date
    Jun 2010
    Posts
    51
    Dynamic SQL is the solution for you.

    e.g.
    Code:
    exec "create table @name (column...)"
    Now that you know how can you use dynamic sql, you should also figure out how to create tables with dynamic columns.

  3. #3
    Join Date
    Sep 2010
    Posts
    8

    Thumbs up Sybase create tables dynamically from values of variables ( tricky )

    Yup, you are correct. That solution worked for me. I have also figured how to add the columns. Thanks a lot for your suggestion. Appreciate your timely help.

Tags for this Thread

Posting Permissions

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