T-SQL - Build temporary table definition dynamical

Results 1 to 2 of 2

Thread: T-SQL - Build temporary table definition dynamical

  1. #1
    Join Date
    Dec 1969

    Default T-SQL - Build temporary table definition dynamical

    The number of (and headings for) columns in the temp table that I am building in a T-SQL stored procedure is not known until I have interrogated the data. If there are 15 months worth of data then there will be 15 columns etc. Is it possible to build a CREATE TABLE definition that uses @variables as field names?

  2. #2
    Join Date
    Dec 1969
    Indianapolis, IN

    Default Not quite...

    You can&#039;t use variables for column names in a CREATE TABLE statement. I do have a couple of suggestions, though. <BR><BR>1. Go ahead and designt he temp table to have the maximum number of columns possible for your usage. So if there are 20 months possible, make 20 columns. Then just use however many you need. Make the names simple like Month1, Month2, etc.<BR><BR>2. Perhaps you don&#039;t need such a temp table. Maybe you just need to GROUP BY periods of time from other results. Just a thought (in case the number of months could be large).

Posting Permissions

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