Wednesday, March 7, 2012

copying a record within the same table...

Hi. I would like to copy some records within the same table. what happens is we get very similar new cases in our office and we want to apply the same information from one client to the new client.

i looked at:
INSERT INTO ClientSpecs (ClientID, Spec1, Spec2, etc.)
SELECT Spec1, Spec2 from ClientSpecs WHERE ClientID=1234
but i want to use the new client id in place of the old client id. is there a way to do this? does this make sense? we're basically copying one client's file to a new client's file, except we need to use the new client's id.INSERT INTO ClientSpecs (ClientID, Spec1, Spec2)
SELECT '123', Spec1, Spec2 from ClientSpecs WHERE ClientID=1234|||thank you for that cfr! i never thought it was going to be that easy. Now, I have another question.

How do I update a Spec from one client to another client. For example, I have

ClientID Spec1 Spec2
1234 1 23
1234 2 12

And I want to copy the first client's Spec2 information to another client.

ClientID Spec1 Spec2
4567 1 NULL
4567 2 NULL

But, I only want to copy the Spec2 information for the client. How would I do this? Does this even make sense?|||Untested:

UPDATE ClientSpecs destTble
SET destTble.Spec2 = (SELECT srcTbl.Spec2
FROM ClientSpecs srcTbl
WHERE srcTbl.ClientID = destTble.ClientID
AND srcTble.Spec1 = destTble.Spec1)
WHERE destTble.ClientID = '4567'

No comments:

Post a Comment