I'm not totally sure how to explain this problem, but hopwfully it will make sense with the code.I have the code that currently works which updates a table based of data from another at a certain date. However i want the date that is used to be different for each row. I want DATEADD(MONTH,rowID,@daytocheck) to be the date to look at, however when i add that to my code, it updates the whole column to the same value.What can I change to make this work?Not sure how much this makes sense, so if you want any more explanation, i'll try and help.@daytocheck = 'Whatever' - datetimeexec('Update TestTableSET Earned_' + @ColName + ' =isnull( (SELECT SUM( Sales.Cost *( (CASE WHEN Sales.SaleDate >= ''' + @daytocheck + ''' THEN 0 WHEN DATEADD(MONTH,Sales.Term,Sales.SaleDate) <= ''' + @daytocheck + ''' THEN DATEDIFF(DAY,Sales.SaleDate,DATEADD(MONTH,Sales.Term,Sales.SaleDate)) ELSE DATEDIFF(DAY,Sales.SaleDate, ''' + @daytocheck + ''') END) /(CAST(DATEDIFF(DAY,Sales.SaleDate,DATEADD(MONTH,Sales.Term,Sales.SaleDate))As Decimal)) ) ) FROM Sales WHERE Sales.InvoiceYear = TestTable.InvYear AND Sales.InvoiceMonth = TestTable.InvMonth),0)')