How to copy a Column of GUID's from one table to another?

  • I would like to copy a column of GUID's from one table to another.

    The code below works but only uses the first GUID.

    set rowcount 100;

    UPDATE Designation

    SET ProfileId = Profiles.Id

    FROM Designation, Profiles

    Profiles Table has

    GUID

    and other non related fields

    Designation Table

    needs the GUID from the Profiles table

    and has other non related fields.

    I would like the 100 Unique GUID'S from the Profile table to be in the Designation table, so there may be a point of common reference.

    I am guessing i need some type of loop with a counter, but i'm not sure how to do this, in this situation.

    Thanks

  • You need to join on something.

    Right now you are doing a cross join and basically putting a random guid in the update.

    What's commun in both tables you can join on?

  • I would expect something in the like of this:

    UPDATE D

    SET ProfileId = P.Id

    FROM Designation D

    INNER JOIN Profiles P ON P.Code = D.Codeand I guess is that you need to make the ProfileId in the Designation table a varchar.

    Ronald HensbergenHelp us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/-------------------------------------------------------------------------2+2=5 for significant large values of 2

  • The common field is the Id.

    I am trying to create a new table with data from another database, and add the Id into the new table.

  • Then insert both columns, or join on the name. Assuming they actually match.

  • I did an insert into, but it adds the data to the end of the existing data, which is why i need to do an sql update, not a sql insert into.

  • Why not do a delete first?

  • You have given me some ideas, let me try a different method.

    Thanks

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply