• NewBornDBA2017 - Tuesday, February 6, 2018 1:09 PM

    Phil Parkin - Tuesday, February 6, 2018 12:43 PM

    NewBornDBA2017 - Tuesday, February 6, 2018 12:37 PM

    Phil Parkin - Tuesday, February 6, 2018 11:24 AM

    add data in a way that it matches customer key

    Please expand on the above.

    Giving you the real scenario. I have table which contains customer information such as name, address, email address etc. What I need to do is I need to add 2 more columns (education and race). We pull the data the website and now I need to make sure that the education and race data is getting stored properly. For example There is a customer Name John Travolta and his education is Master in CIS and he is white. How do I store those values for let's say 1.5 customers? So when we pull the data for a customer, we have all the information. Does it make sense?

    Sure it makes sense. But which bit do you require assistance with?
    1) How to add columns to tables?
    2) How to populate columns from data held in other tables?
    3) How to transfer data from a web form to a SQL Server database table?

    So the 1st part is done, but I need help with the second part. How to populate the race and education data based on the customer key?
    Or is it better to have a separate column for race and education but I am not sure if that's going to make any sense. It will only make sense if someone has multiple race or even multiple education. But if are only concerned about 1 record of education (highest degree and not bachelor's or master's or PhD etc.), then adding 2 columns into an existing table should work.

    Regarding adding multiple columns for race and education, that's a design choice for you to make. But if you find yourself creating more than a couple of either, you're rapidly heading into a bad place & should seriously consider normalising your design.
    Regarding the query: without a full description of table or column names, the general structure is as follows:
    UPDATE target
    SET MaritalStatus = source.MaritalStatus
    FROM DatFileBak target
    JOIN Tab2 source on target.CustomerKey = source.CustomerKey

    The above query assumes a 1-1 link between the source and target tables on the match key ... this is very important.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.