Results 1 to 2 of 2

Thread: INSERT based on another record's data

  1. #1
    Join Date
    Nov 2010
    Posts
    3

    Question INSERT based on another record's data

    OK, maybe I didn't describe my problem the right way, or I am now making some progress figuring it out by myself...

    Here's my need:

    I have a table, called attributes, which contains just 3 fields:

    userid, attributeid and value

    I have records holding data that I want to split and create other records with, using an INSERT statement. Here's an example, from this record :

    userid ; attributeid ; value
    1 ; 14 ; 2000-11-29

    I want to AUTOMATICALLY create these 2 records (in one or 2 queries, I don't mind) :

    userid ; attributeid ; value
    1 ; 33 ; 11 (or November)
    1 ; 34 ; 29

    Of course, if I have 100 records with attribute '14' set to a date, I want to be able to create 200 records (with attribute 33/34) in a single or 2 queries at the most.

    I am guessing that is feasible in SQL, but I read that 'WHERE' clause cannot be used in an INSERT statement. How can I achieve the same goal ?

    Any help will be greatly appreciated.

    Thanks in advance.

    Marco

  2. #2
    Join Date
    Feb 2011
    Posts
    6
    Would this work?:

    The first query:

    Insert into attributes select userid, 33, month(value) from attributes;

    and the second query:

    Insert into attributes select userid, 34, day(value) from attributes where attributeid <> 33;

    Bert

Posting Permissions

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