Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Creating a temporary table

Creating a temporary table

Scheduled Pinned Locked Moved Database
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fly904
    wrote on last edited by
    #1

    Hi, I have a table which looks like the following.

    OriginalTable
    OriginalTable_Id(pk) OriginalTable_Name(unique)

    1 NewColumnName1
    2 NewColumnName2
    ...

    I need to make it look like this table below dynamically:

    NewTable
    NewTable_Id(pk) NewColumnName1 NewColumnName2 ...

    I know I need to create a new tempory Table (using tempDB?), but I don't know how to get the values in the table to be the new column names. I have this at the moment:

    CREATE TABLE NewTable
    (
    NewTable_Id INT PRIMARY KEY,

    ???

    )

    ???: Would it be something like: SELECT OriginalTable_Name FROM OriginalTable Any tutorials or advice would be greatly appreciated. Thanks in advance.

    hmmm pie

    S 1 Reply Last reply
    0
    • F fly904

      Hi, I have a table which looks like the following.

      OriginalTable
      OriginalTable_Id(pk) OriginalTable_Name(unique)

      1 NewColumnName1
      2 NewColumnName2
      ...

      I need to make it look like this table below dynamically:

      NewTable
      NewTable_Id(pk) NewColumnName1 NewColumnName2 ...

      I know I need to create a new tempory Table (using tempDB?), but I don't know how to get the values in the table to be the new column names. I have this at the moment:

      CREATE TABLE NewTable
      (
      NewTable_Id INT PRIMARY KEY,

      ???

      )

      ???: Would it be something like: SELECT OriginalTable_Name FROM OriginalTable Any tutorials or advice would be greatly appreciated. Thanks in advance.

      hmmm pie

      S Offline
      S Offline
      Syed Mehroz Alam
      wrote on last edited by
      #2

      Have a look at pivot clause here[^] Regards, Syed Mehroz Alam

      My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

      F 1 Reply Last reply
      0
      • S Syed Mehroz Alam

        Have a look at pivot clause here[^] Regards, Syed Mehroz Alam

        My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

        F Offline
        F Offline
        fly904
        wrote on last edited by
        #3

        Brilliant, that's exactly what I was looking for thanks alot. But how can I get the name of the columns dynamically. eg. The value is '198' so how can I make it the column name without knowing the value? Edit: Thanks again for your help. Two minutes after posting this reply and Googleing 'Dynamic Pivots' I found this[^] which solved my problem. Sorry for the inconvenience.

        hmmm pie

        modified on Wednesday, April 22, 2009 2:15 PM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups