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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:56:35+00:00 2026-05-29T18:56:35+00:00

I have a fairly easy SQL task at hand and I’d like validation (or

  • 0

I have a fairly easy SQL task at hand and I’d like validation (or guidance) for the solution I came up with. Thank you for helping! (this is my first post)

Here’s the problem I’m facing (simplified):

I’m importing user information from a flat file into a staging table (using SSIS). Each user will have 2 or 3 records. Each line will contain important data. The end result needs to be 1 record per customer that contains info from all 3.

Here’s an example of the data:

PK |    Name   | UniqueCustID | Info1 | Info2  | Info3 |
----------------------
1   | John Doe  |    12345     |  Opt1  |  NULL |  NULL
2   | John Doe  |    12345     |  NULL  |  Opt2 |  NULL
3   | John Doe  |    12345     |  NULL  |  NULL |  Opt3

The final result needs be be something like this:

 PK |    Name   | UniqueCustID | Info1 | Info2  | Info3 |
----------------------
1   | John Doe  |    12345     |  Opt1  |  Opt2 |  Opt3

I’m trying to keep this as simple as possible. I want to handle this with a basic Execute SQL task in SSIS (or a couple). What are people’s jump-to reactions? Can I provide any additional information? Thank you again.

UPDATE – To show the two step process I am trying:

1) This should make all of the individual customer sets match:

WITH CustInfoTMP (UniqueCustID,Info1,Info2,Info3)
AS
    (
    SELECT UniqueCustID,MAX(Info1),MAX(Info2),MAX(Info3)
    FROM CustStaging
    GROUP BY UniqueCustID 
    )
UPDATE CustStaging 
SET 
    CustStaging.Info1 = CustInfoTMP.Info1
    CustStaging.Info2 = CustInfoTMP.Info2
    CustStaging.Info3 = CustInfoTMP.Info3
FROM CustStaging
INNER JOIN CustStagingTMP ON CustStaging.UniqueCustID = CustStagingTMP.UniqueCustID

2) I then using this to delete duplicate records:

DELETE
FROM CustStaging 
WHERE UniqueCustID NOT IN
    (
    SELECT MAX(PK) 
    FROM CustStaging 
    GROUP BY UniqueCustID
    )

I hope everyone is following this. I really appreciate the feedback.

  • 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-29T18:56:39+00:00Added an answer on May 29, 2026 at 6:56 pm

    How about this?

    CREATE TABLE TargetTable_tbl
    ( ID INT IDENTITY(1,1) ,
      Name  varchar(100),
      Info1 varchar(10),
      Info2 varchar(10),
      Info3 varchar(10)
    )
    go
    
    insert TargetTable_tbl 
    
    select distinct Name, Info1, Info2, Info3
    from StagingTable_tbl ST
    left join 
    ( select distinct Name, Info1
      from StagingTable_tbl 
      where Info1 is not null ) I1 on ST.Name = I1.Name
    left join 
    ( select distinct Name, Info2
      from StagingTable_tbl 
      where Info2 is not null ) I2 on ST.Name = I2.Name
    left join 
    ( select distinct Name, Info3
      from StagingTable_tbl 
      where Info3 is not null ) I3 on ST.Name = I3.Name
    go  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly inexperienced in SQL and this seems like it must be an easy
So I just set this up: http://www.phpeasystep.com/phptu/6.html It was fairly easy, now I have
I have a form where fields get added via JavaScript. This is fairly easy
This might be fairly easy to answer. I have two scripts (i.e. ScriptA.app and
I'm sure there's a fairly easy way to do this. I have an the
I believe task I am trying to accomplish is fairly easy, but I have
I'm fairly new to ASP MVC so go easy :). I have a form
I have a fairly standard inheritance situation in my current LINQ-to-SQL project. I have
This is a fairly easy one, but I cant seem to figure it out.
I've got a, I think fairly easy question, but this is bugging me for

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.