Reputation: 194
I'm trying to uodate a column in table , depending on combination of two columns.If the value was null , since beginning of time I set it to 0 otherwise I set it to max value until that date.I'm using SQL SERVER 2008.Thanks for the help in advance!
update Table1
set value = a.value
from
( SELECT product,
week ,
case when value is null then
(case when max(value) over(PARTITION BY product ORDER BY week ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) is null then 0
else (max(value) over (PARTITION BY product ORDER BY week ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) end )
else value end as value
from table2 ) a
where a.product = table1.product
and a.week = table1.week
Upvotes: 0
Views: 37
Reputation: 2989
The ROWS
keyword was added to the OVER
clause in 2012. You won't be able to use it for 2008.
https://msdn.microsoft.com/en-us/library/ms189461(v=sql.110).aspx
Upvotes: 1