Results 1 to 3 of 3

Thread: SQL assistance

  1. #1
    Join Date
    Jun 2005
    Location
    Waukesha WI
    Posts
    78

    Unanswered: SQL assistance

    I'm a stumped beginer.
    I have TABLE1 with fields: ID, Source, Date_Entered
    I have TABLE2 that is the destination table and has a field called Specialty
    I have TABLE3 that has an ID field and other data to be transformed and entered into TABLE2.

    I wish to populate the Field Specialty with a 'Y' when the data comes in if TABLE3.ID is in TABLE1 and the TABLE1.source = 'ABC' and the TABLE1.Date_Entered = to_date('06012006','MMDDYYYY')

    I use a SQL statement to transform and load that is structured like:
    INSERT INTO TABLE2
    ( FIELD_T2_1, FIELD_T2_2, FIELD_T2_3...)
    SELECT
    (FIELD_T3_1, FIELD_T3_2, FIELD_T3_3...)
    FROM TABLE 3

    Of course I utilize DECODE() and other calculations in the FIELD_T3_ s
    to put the data in the right format.
    But I just cant seem to figure this one out. Nor can I figure out how to test it.

    I used to do it with a NOT EXISTS() statement after everything was loaded, but that was before I added the DATE_ENTERED and SOURCE. That's hosing me.

    Any ideas?

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Perhaps something like this?
    Code:
    INSERT INTO table2
      (col1, col2)
      (SELECT t3.col1, t3.col2
       FROM table3 t3
       WHERE t3.id IN (SELECT t1.id 
                       FROM table1 t1
                       WHERE t1.source = 'ABC'
                         AND t1.date_entered = TO_DATE('06012006', 'MMDDYYYY')
                      )
      );

  3. #3
    Join Date
    Jun 2005
    Location
    Waukesha WI
    Posts
    78
    The problem is that I just want to flag the Specialty field if it exists in the list.
    I want to bring them ALL into table2, not only the ones with the parameters mentioned.

    How do I set a field to a value dependent on whether another field exists in a select statement?

Posting Permissions

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