I have a table that looks something like the following:
Row Cust date1 date2 key daysdiff
1 A 1/1/2010 1/14/2010 x
2 A 1/21/2010 1/31/2010 y
3 B 1/7/2010 1/10/2010 x
4 B 2/1/2010 2/3/2010 y
I need to loop through the table and calculate the value for the 'daysdiff' column based on the values in the 'Cust' and 'key' columns. Cust must equal Cust, and key must equal 'y'.
So, in the above example, the daysdiff value for row 2 should equal 7, and for row 4, it should be 22. There should be null values for rows 1 and 3.
I think I need a self join with my update statement, but I'm not getting it quite right. Any assistance is welcome.
Thanks in advance.