UPDATE - Help!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lewe22
    New Member
    • Sep 2007
    • 94

    UPDATE - Help!!

    When performing the following update:
    UPDATE learner_ilr l
    SET l.prior_attain_ level =
    (SELECT p.prior_attain_ level
    FROM people p
    WHERE p.person_code = l.person_code
    AND p.prior_attain_ level IS NOT NULL)
    WHERE
    l.prior_attain_ level IS NULL AND
    l.funding_year = 13

    the section in bold is being ignored. Is there a logical reason why this might be happening? Have i written the update incorrectly?
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by Lewe22
    When performing the following update:
    UPDATE learner_ilr l
    SET l.prior_attain_ level =
    (SELECT p.prior_attain_ level
    FROM people p
    WHERE p.person_code = l.person_code
    AND p.prior_attain_ level IS NOT NULL)
    WHERE
    l.prior_attain_ level IS NULL AND
    l.funding_year = 13

    the section in bold is being ignored. Is there a logical reason why this might be happening? Have i written the update incorrectly?
    try:


    Code:
        UPDATE learner_ilr l
        SET l.prior_attain_level = 
        FROM people p INNER JOIN  p.person_code = l.person_code 
        WHERE
        p.prior_attain_level IS NOT NULL
        AND
        l.prior_attain_level IS NULL AND
        l.funding_year = 13

    Comment

    • Lewe22
      New Member
      • Sep 2007
      • 94

      #3
      That doesn't work, error 'missing expression' at FROM.

      I've spent a long time trying to figure this out and in particular it is the position of the FROM that i can't get to work.

      Created in Access the structure of the query works like:
      UPDATE table1 INNER JOIN table2
      ON table1.field1 = table2.field2
      SET table1.fieldx = table2.fieldn
      WHERE conditions...

      The same structure does not work as a SQL pass through query though and i don't really understand where to declare table2 (people) peoperly.
      At the moment i am declaring it in the sub query but realise it needs to be declared somewhere in the main update. HELP!!
      UPDATE learner_ilr l
      SET l.prior_attain_ level =
      (SELECT p.prior_attain_ level
      FROM people p
      WHERE p.person_code = l.person_code
      AND p.prior_attain_ level IS NOT NULL)
      WHERE
      l.prior_attain_ level IS NULL AND
      l.funding_year = 13

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Originally posted by ck9663
        try:


        Code:
            UPDATE learner_ilr l
            SET l.prior_attain_level = 
            FROM people p INNER JOIN  p.person_code = l.person_code 
            WHERE
            p.prior_attain_level IS NOT NULL
            AND
            l.prior_attain_level IS NULL AND
            l.funding_year = 13
        let's do that again....

        Code:
              UPDATE learner_ilr l
                  SET l.prior_attain_level = p.prior_attain_level
                  FROM people p INNER JOIN  p.person_code = l.person_code
                  WHERE
                  p.prior_attain_level IS NOT NULL
                  AND
                  l.prior_attain_level IS NULL AND
                  l.funding_year = 13
        --CK

        Comment

        • Lewe22
          New Member
          • Sep 2007
          • 94

          #5
          I did try that but it still didn't work! Same error message!

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            Originally posted by Lewe22
            I did try that but it still didn't work! Same error message!
            i think what ck9663 meant was
            [CODE=sql]UPDATE learner_ilr l
            SET l.prior_attain_ level =(select p.prior_attain_ level
            FROM people p INNER JOIN p.person_code = l.person_code
            WHERE
            p.prior_attain_ level IS NOT NULL
            AND
            l.prior_attain_ level IS NULL AND
            l.funding_year = 13)[/CODE]
            Please try to correct the code youself.

            cheers

            Comment

            Working...