Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:43:39+00:00 2026-05-24T13:43:39+00:00

Within SQL Server 2005, I need to create a table dynamically based upon the

  • 0

Within SQL Server 2005, I need to create a table dynamically based upon the rows returned from a query.

For example:

SELECT * FROM TableA 

returns the following rows

  1. Forename
  2. Surname
  3. DOB

And I’d like a table created like so:

Forename, Surname, DOB.

I plan to use this procedure on a number of different sources therefore the returned rows will be different each time.

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:43:40+00:00Added an answer on May 24, 2026 at 1:43 pm

    I would use SELECT INTO in conjunction with PIVOT:

    See:

    • http://msdn.microsoft.com/en-us/library/ms177410.aspx
    • http://www.devguru.com/technologies/t-sql/7126.asp
    • http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx

    I don’t have access to SQL Server right now, but I would go for something like this (based on the links above):

    SELECT [0] 
    INTO TableB
    FROM
        ( SELECT id, colName FROM TableA ) AS SourceTable
    PIVOT
        ( AVG(id) FOR colName IN [0] ) AS PivotTable;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I writing a query within ms sql server 2005 and having some trouble getting
I have a SQL Server 2005 table called 'Contracts': CREATE TABLE Contracts ( ContractNo
I need to pull some BLOB data from a SQL Server 2005 database and
Within our Active Directory domain, we have a MS SQL 2005 server, and a
I have stored procedures in SQL Server T-SQL that are called from .NET within
I need to manage the trace files for a database on Sql Server 2005
I need to automate the migration from an Access (2003) to an SQL Server
In Microsoft SQL Server 2005, there is the option to store within the database
I need to write a web application using SQL Server 2005, asp.net, and ado.net.
I work on an Internet-facing, ASP.NET-based product that uses SQL Server 2005. Most customers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.