Re-doing a giant, old, crusty sp. So here's a questions for all of you. I have two temp tables: #temp_acct_codes and #temp_hour_tracker.
#temp_acct_codes contains these two columns in addition to a slew of others: week, hours, date_worked. #temp_hour_tracker contains week, hours_already_worked, 1_0_hrs, 1_5_hrs, 2_0_hrs, diff_hrs, eper_hrs, loc (different types of hours).
#temp_hour_tracker is suppose to hold the week (using date part) and sum any hours. The idea is to compare these two tables and
a) #temp_hour_tracker doesn't contain the week(s) that the other one does, then insert new row (insert week, hours, and other details).
b)if they have week in common, let's update hours_already_worked (sum it with existing number) in #temp_hour_tracker using cases.
That's not all for case b and gets more complicated, but I'm tackling case A. So for case A, I know I can do somethin glike the following:
--get case a entries (entries that don't exist in #temp_hour_tracker select * from #temp_acct_codes a outer left join #temp_hour_tracker b on b.week = a.week where b.week = null --so collectively, would it be something like: INSERT INTO #temp_hour_tracker VALUES(_, _, _, and so on) WHERE ( /* insert above query */
Ok, so I haven't an idea how to merge all this together. Would someone mind giving me a helping hand? TIA.