Re: Merge Statement

From: ddf <oratune_at_msn.com>
Date: Tue, 3 Feb 2009 12:06:18 -0800 (PST)
Message-ID: <41c7a873-f96f-42f6-b6df-ad6f19c774b8_at_o40g2000prn.googlegroups.com>



On Feb 3, 7:59�am, Mtek <m..._at_mtekusa.com> wrote:
> On Feb 2, 3:12�pm, ddf <orat..._at_msn.com> wrote:
>
>
>
>
>
> > On Feb 2, 2:06�pm, Mtek <m..._at_mtekusa.com> wrote:
>
> > > I have this merge statement:
>
> > > � � �MERGE INTO rank_history_new zrh
> > > � � � �USING (SELECT v_id AS new_m_ticker, v_rec.z_rank_d AS new_rank
> > > FROM dual) zrh2
> > > � � � � �ON (zrh.m_id = v_id AND rank = v_rec.z_rank_d)
> > > � � � �WHEN NOT MATCHED THEN
> > > � � � � �INSERT (m_id, rank, time, add_del_flag)
> > > � � � � �VALUES (v_id, v_rec.z_rank_d, v_rank_date, v_add_del_flag);
>
> > > It does not work 100%. �Actually what I want is to compare it with the
> > > LAST entry for the v_id. �So, if I have the following. �So if there
> > > are 4 entries for a given ID, I want to compare it against the last
> > > entry.
>
> David,
>
> In this case, rank_history_new has several records for each ID. �There
> is also a DATE on those records. �When performing the MERGE, I want to
> compare against the record with the MAX date for that ID.
>
> ID � � DATE
> -----------------
> A � � 6/3/08
> A � � 9/7/08
> A � � 1/5/09 � � <-- Use this one in the MERGE statement.
>
> So again, back to the merge statement, I am comparing 'rank' values,
> but I want to perform that compare on the record with the MAX date for
> that ID.
>
> Does this help a bit in my explanation?- Hide quoted text -
>
> - Show quoted text -

Can you provide DDL for the tables and some sample data?

David Fitzjarrell Received on Tue Feb 03 2009 - 14:06:18 CST

Original text of this message