UPDATE Statement

  • Hello,

    I have 2 tables

    TABLE 1

    • id
    • name
    • department
    • startdate
    • enddate
    • ruleinapplication

    TABLE 2

    • id2
    • name
    • month
    • department
    • other data

    I'd like to update DEPARTMENT for each month in TABLE2 with the value of the department in TABLE 1

    Thanks

  • can you say what happens when:

    1. a department on table1 has startdate and endate difference of more than 1 month

    2. when the year rolls over?

    3. if more than 1 department have the same month number in table1

     


    * Noel

  • 1 & 2  : month is a number YYYYMM (unique identifier= a period).

    startdate is a period

    3 : I always have enddate of a record = start of a record for a same name. and the dapartment may be the same or a different.

  • UPDATE Table2 SET Department = Table1.Department

    FROM TABLE1

    Where Table2.month =Table1.StartDate

    without some examples of the data this is what I can suggest.

     


    * Noel

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply