I have 2 tables
First Table has ff. structure and sample data
coID smPID PersonID KeyCode Alpha NDate XDate YDate
0 1 32322 28 4/1/2009
0 1 32322 49 8/4/2005
0 1 32322 60 Yes
0 1 92888 28 7/1/2005
0 1 92888 60 Yes
0 1 92888 37 10/1/2009
Second Table
Person ID prmDate Completed Date_paid report_date
82333 6/1/2000 4/5/2001 8/1/2001
32322 4/1/2009 Yes 8/4/2005
92888 7/1/2005 Yes 10/1/2009
Question; Id like to create a Insert stored procedure that would output to the first table based on the data
on second table.
For example for personID 32322 in second table if field prmDate is populated('4/1/2009') it would insert 28 in the keycode and '4/1/2009' in the Ncode. This action can be done only if prmDate does not exist in first table. If keycode 28 already exists in first table, ignore it and do not insert Same logic also apply Date_paid(XDate in first table) and report Date. It would insert 49,60 depending what dates are populated in second table.
Generally First table can have mulitple records for same ID. I m assuming that the stored procedure will
have many INsert statements for each Date to test if exists...
I have about many records to loop and apply the stored procedure.
Please ask question if not clear.
Open in new window