Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2013
    Posts
    9

    Unanswered: Newbie: Copy rows within a table

    Hi

    I'm new to my job in a tiny company maintaining a POS system. It uses MF COBOl with DB2 database. The database interaction is all done in separate programs for each table and it appears that the system was 'layered' a long time ago. Unfortunately there is nobody here I can ask about things. Yes, the job is difficult.

    I'm pretty new to SQL as I have only ever used ISAM files although I have experimented. Simple question:

    I am creating a new depot code/record in the system which is actually done by copying from one depot code to another. There is a stock levels file with the key consisting of depot code and product code. So, if I am copying depot code 123 to depot code 456 I need to copy all of the entries for 123 to 456, retaining the product code (obviously) and re-setting some other fields (stock count level, name last accessed, etc). Could somebody please advise me of the syntax for this? I THINK, it is something like:

    INSERT INTO STOCKLEVELS (NEW_DEPOT_CODE, PRODUCT_CODE, 0,' ') (SELECT DEPOT_CODE, PRODUCT_CODE FROM STOCKLEVELS WHERE DEPOT_CODE = OLD_DEPOT_CODE)

    I appreciate all help as this is my first post.

    Regards

    I

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Your INSERT statement syntax is not correct. It should look something like:
    Code:
    INSERT INTO yourtable (column_name_1, column_name_2, ...)
    SELECT <as many columns or values as the columns you are inserting>
    FROM table WHERE whatever
    You cannot have literals in your column list, like 0 or ' ' - only the names of columns you're inserting into. The literals can be present in the SELECT list.
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Jan 2013
    Posts
    9
    Forgot to say thanks very much for the reply. All works tickety boo.

Posting Permissions

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