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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:45:01+00:00 2026-05-17T18:45:01+00:00

I am working with a database schema that I cannot change – and I

  • 0

I am working with a database schema that I cannot change – and I need to run a bulk update. I am moving data between source and target databases, with the same schema. I know this is awful, but it is what I am working with right now.

The schema is as follows:

Car
CarType1
CarType2
CarType3
CarType4

What I am trying to do – is bring over the CarTypes from my source database, by updating the target CarTypes.

My question is:

If my source record for car “BMW” has 3 CarTypes specified like so:

Car: BMW
CarType1: Fast
CarType2: Well Made
CarType3: Good Handling
CarType4: NULL

and my target has:

Car: BMW
CarType1: Fun Car
CarType2: NULL
CarType3: NULL
CarType4: NULL

How would I write an update statement such that CarType1-2-3 from the source would fill in the available NULL fields on the target? So Source:CarType1 -> Target:CarType2. And also – would there be a way to cancel out of the bulk update for this record and log a message if there wasn’t room in the target for all of the source fields(say if there’s 4 CarType values in my source, and only 3 NULL CarType columns in the corresponding target row?

Thank you!

  • 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-17T18:45:02+00:00Added an answer on May 17, 2026 at 6:45 pm

    I don’t know about doing it in one statement but four UPDATE statements do the trick.
    The final select shows you what columns have overflowed.

    DECLARE @CarsSource TABLE (Car VARCHAR(32), CarType1 VARCHAR(32), CarType2 VARCHAR(32), CarType3 VARCHAR(32), CarType4 VARCHAR(32))
    DECLARE @CarsDestination TABLE (Car VARCHAR(32), CarType1 VARCHAR(32), CarType2 VARCHAR(32), CarType3 VARCHAR(32), CarType4 VARCHAR(32))
    
    INSERT INTO @CarsSource VALUES ('BMW', 'Fast', 'Well Made', 'Good Handling', NULL)
    INSERT INTO @CarsSource VALUES ('Overflow', 'Fast', 'Well Made', 'Good Handling', 'Overflow')
    
    INSERT INTO @CarsDestination VALUES ('BMW', 'Fun Car', NULL, NULL, NULL)
    INSERT INTO @CarsDestination VALUES ('Overflow', 'Fun Car', NULL, NULL, NULL)
    
    UPDATE  @CarsDestination
    SET     CarType1 = s.CarType1
            , CarType2 = s.CarType2
            , CarType3 = s.CarType3
            , CarType4 = s.CarType4
    FROM    @CarsDestination d
            INNER JOIN @CarsSource s ON s.Car = d.Car
    WHERE   d.Cartype1 IS NULL        
    
    UPDATE  @CarsDestination
    SET     CarType2 = s.CarType1
            , CarType3 = s.CarType2
            , CarType4 = s.CarType3
    FROM    @CarsDestination d
            INNER JOIN @CarsSource s ON s.Car = d.Car
    WHERE   d.Cartype2 IS NULL        
    
    UPDATE  @CarsDestination
    SET     CarType3 = s.CarType1
            , CarType4 = s.CarType2
    FROM    @CarsDestination d
            INNER JOIN @CarsSource s ON s.Car = d.Car
    WHERE   d.Cartype3 IS NULL        
    
    UPDATE  @CarsDestination
    SET     CarType4 = s.CarType1        
    FROM    @CarsDestination d
            INNER JOIN @CarsSource s ON s.Car = d.Car
    WHERE   d.Cartype4 IS NULL        
    
    SELECT  *
    FROM    @CarsSource s
            LEFT OUTER JOIN @CarsDestination d ON COALESCE(d.Cartype4, d.Cartype3, d.Cartype2, d.Cartype1) = COALESCE(s.Cartype4, s.Cartype3, s.Cartype2, s.Cartype1)
    WHERE   d.Car IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on scripts that apply database schema updates. I've setup all my SQL
I am working on some schema changes to an existing database. I backed up
I am working on a database application that runs on various independent servers. Each
I'm working on a database that needs to represent computers and their users. Each
I'm working on a database in SQL Server 2000 that uses a GUID for
I'm working on a database project and I need to create Outlook 2007 plugin
I'm working on database designs for a project management system as personal project and
I've been working on database-driven web applications for a few years now and recently
I'm working on a database for a small web app at my school using
I'm working on a database design for groups hierarchy used as the foundation of

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.