September 20, 2011 at 2:59 pm
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
September 20, 2011 at 3:04 pm
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?
September 20, 2011 at 3:13 pm
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
September 20, 2011 at 3:16 pm
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.
September 20, 2011 at 3:18 pm
Then insert both columns, or join on the name. Assuming they actually match.
September 20, 2011 at 3:28 pm
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.
September 20, 2011 at 3:31 pm
Why not do a delete first?
September 20, 2011 at 3:34 pm
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