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 9250327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:25:16+00:00 2026-06-18T10:25:16+00:00

I have an old database that is a single flat table. I want to

  • 0

I have an old database that is a single flat table. I want to copy the old data to the new db structure. Both are MSSQL databases. Here’s a simplified example of what I want to do:

OLD_DB                                     New_DB

Customers_Table             Customers_Table         Phone_Numbers
---------------             --------------          -------------  
FirstName                   CustomerID              PhoneNumberID
LastName          -->       FirstName               CustomerID
PhoneNumber1                LastName                PhoneNumber
PhoneNumber2
PhoneNumber3

I understand how to copy the flat data. This seems to work just fine:

INSERT INTO   New_DB.dbo.Customers_Table (FirstName, LastName)
SELECT        FirstName, LastName
FROM          OLD_DB.dbo.Customers_Table

I just don’t know how to get the phone numbers into the new structure.

  • 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-06-18T10:25:17+00:00Added an answer on June 18, 2026 at 10:25 am

    If your FirstName and LastName are your unique identifiers, you can run this using UNION after you run your above statement:

    INSERT INTO New_DB.dbo.Phone_Numbers (CustomerId, PhoneNumber)
    SELECT C.CustomerID, OldC.PhoneNumber1
    FROM New_DB.dbo.Customers_Table C
      JOIN OLD_DB.dbo.Customers_Table OldC ON C.FirstName = OldC.FirstName 
         AND C.LastName = OldC.LastName 
         AND OldC.PhoneNumber1 IS NOT NULL
    UNION
    SELECT C.CustomerID, OldC.PhoneNumber2
    FROM New_DB.dbo.Customers_Table C
      JOIN OLD_DB.dbo.Customers_Table OldC ON C.FirstName = OldC.FirstName 
         AND C.LastName = OldC.LastName 
         AND OldC.PhoneNumber2 IS NOT NULL
    UNION
    SELECT C.CustomerID, OldC.PhoneNumber3
    FROM New_DB.dbo.Customers_Table C
      JOIN OLD_DB.dbo.Customers_Table OldC ON C.FirstName = OldC.FirstName 
         AND C.LastName = OldC.LastName 
         AND OldC.PhoneNumber3 IS NOT NULL
    

    Alternatively, you could use UNPIVOT and run something like this (I’ve condensed it for testing, but same concept):

    SELECT Id, Phone 
    FROM ( SELECT id, phone1, phone2, phone3 FROM Phone ) p
    UNPIVOT
    (Phone FOR Phones IN (phone1, phone2, phone3))AS Phone
    

    Here is the SQL Fiddle for the UNPIVOT:

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an old SQL Server 2000 database that I want to get into
I have a database with a lot of old phpBB data that contains posts
I have a database with a lot of old phpBB data that contains posts
I have several (old) Drupal-sites that need to be replaced with one single new
I have only ever dealt with database querys before in the old fashion that
I have an old database and a new database. The old records were converted
I have this old Access database (2000 format) which i want to convert to
We have a SQL Server database table that consists of user id, some numeric
I have an old database with a gazillion records (more or less) that have
I am using WAMP and i have a table in my database that needs

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.