larrydavid
Programmer
Hello,
I am updating records that are filtered for a particular month/year like so:
However, I need to do this for Jan 2010 through Dec 2011 and realize this means I need 24 update statements for each metric and I have 12 metrics. I've been looking at looping through cursors and tried playing around with CASE WHEN THEN statements, but I'm not sure how to loop through a cursors and the CASE statements still end up being very long.
I would like to avoid having to write 288 update statements so if someone could please show me an easier way, hopefully with a set-based approach I would really appreciate it.
Thanks,
Larry
I am updating records that are filtered for a particular month/year like so:
Code:
UPDATE
Profile_Metrics_Line_Chart_Temp
SET
Dollars_Billed_Current = cl.metricValue
FROM
CHART_DATA_Temp cl
WHERE
Profile_Metrics_Line_Chart_Temp.tin9 = cl.tin9 AND
Profile_Metrics_Line_Chart_Temp.suffix = cl.suffix AND
cl.metric = 'Dollars_Billed_Current' AND
cl.monthYear = 'Jan 2010'
UPDATE
Profile_Metrics_Line_Chart_Temp
SET
Dollars_Billed_Current = cl.metricValue
FROM
CHART_DATA_Temp cl
WHERE
Profile_Metrics_Line_Chart_Temp.tin9 = cl.tin9 AND
Profile_Metrics_Line_Chart_Temp.suffix = cl.suffix AND
cl.metric = 'Dollars_PAID_Current' AND
cl.monthYear = 'Jan 2010'
However, I need to do this for Jan 2010 through Dec 2011 and realize this means I need 24 update statements for each metric and I have 12 metrics. I've been looking at looping through cursors and tried playing around with CASE WHEN THEN statements, but I'm not sure how to loop through a cursors and the CASE statements still end up being very long.
I would like to avoid having to write 288 update statements so if someone could please show me an easier way, hopefully with a set-based approach I would really appreciate it.
Thanks,
Larry