Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    165

    Unanswered: 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:
    Code:
    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.

  2. #2
    Join Date
    Nov 2004
    Posts
    128
    INSERT INTO ClientSpecs (ClientID, Spec1, Spec2)
    SELECT '123', Spec1, Spec2 from ClientSpecs WHERE ClientID=1234

  3. #3
    Join Date
    Jan 2005
    Posts
    165
    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

    Code:
    ClientID  Spec1  Spec2
    1234      1      23
    1234      2      12
    And I want to copy the first client's Spec2 information to another client.
    Code:
    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?

  4. #4
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    65
    Untested:

    Code:
    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'
    Retired Moderator at Xtreme VB Talk, for all of your Visual Basic needs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •