Results 1 to 2 of 2

Thread: Copy column to new table

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    736

    Copy column to new table

    Hi but confused here i have MS Sql server express 2005. what i was hoping to do was to copy a column from one table to another in the same DB basically both tables have a link key so i wanted to just add the data not the key, but obviously i wanted to add the data to the correct rows. tried this but i am getting an error saying that the column "OTHERSTUFF"does not exist and i know it does.

    Code:
    Dim StrSql As String
                
                
                StrSql = "INSERT INTO Table_WARE (MYSTUFF) SELECT MYSTUFF FROM Table_OTHERS WHERE MYSTUFFKEY=OTHERSKEY;"
                rs.Open StrSql, cn, , adLockPessimistic, adCmdText
    Both tables have the data in them and allready have the columns one empty ofcoures ready to recieve the data i know i was given a example in a previous but this was for a differnt application and selects all the records i only want to add one column

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Copy column to new table

    An Insert will Insert an entirely new record (or multiple).

    An Update will Update an existing record (or multiple).


    I think this is what you want (syntax may not be quite right, check Books Online for Update if it doesn't work!):
    Code:
    UPDATE Table_WARE 
    SET MYSTUFF = Table_OTHERS.MYSTUFF 
    WHERE Table_OTHERS.MYSTUFFKEY=OTHERSKEY
    FROM Table_OTHERS

Posting Permissions

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



Click Here to Expand Forum to Full Width