0

I want to update a temp table based on another table result set.

Any suggestions. The select query works independently. But I am thinking to integrate with the update statement.

UPDATE #person_membership_promo_ext 
SET note_about=
(
    select note_text
    FROM note nt 
    INNER JOIN #person_membership_promo_ext per
      ON per.person_id=nt.main_ref_id
        and per.membership_type='P'
        and note_id=(select MAX(note_id)from note nt_1
    where nt_1.main_ref_id=per.person_id)
) 
user2989408
  • 3,127
  • 1
  • 17
  • 15
user3120927
  • 17
  • 1
  • 2
  • 8

3 Answers3

0
UPDATE per
SET note_about=nt.note_text
FROM note nt 
INNER JOIN #person_membership_promo_ext per
  ON per.person_id=nt.main_ref_id
    and per.membership_type='P'
    and note_id=(select MAX(note_id)from note nt_1
where nt_1.main_ref_id=per.person_id)
user172839
  • 1,035
  • 1
  • 10
  • 19
0

You can use joins in update statements

UPDATE per
SET note_about = nt.note_text
FROM #person_membership_promo_ext per
INNER JOIN note nt
  ON per.person_id=nt.main_ref_id
    and per.membership_type='P'
    and note_id = (
        select MAX(note_id) 
        from note nt_1
        where nt_1.main_ref_id = per.person_id
   )
Umair
  • 3,063
  • 1
  • 29
  • 50
0

Here you go,

Update per
set per.note_about = nt.note_text
FROM note nt 
INNER JOIN #person_membership_promo_ext per
ON per.person_id=nt.main_ref_id
and per.membership_type='P'
and note_id=(select MAX(note_id)from note nt_1
where nt_1.main_ref_id=per.person_id)

I hope this will help!

Dattatray Kale
  • 81
  • 1
  • 1
  • 6