Reputation: 1
This works with SELECT
:
(LEAD(AltCode,2) OVER (ORDER BY AltCode) ) from [clroot].[Material]
but not with Update
USE [MEKON-EPE]
UPDATE [clroot].Material
SET String1 = (LEAD(AltCode, 2) OVER (ORDER BY AltCode))
FROM [clroot].[Material]
I get this error:
Msg 4108, Level 15, State 1, Line 6
Windowed functions can only appear in the SELECT or ORDER BY clauses.
I want to update a specific column with the value of the value of next 2 columns.
Upvotes: -1
Views: 268
Reputation: 82010
Just to expand on my comment
with cte as (
Select *
,NewVal = LEAD(AltCode,2) OVER (ORDER BY AltCode)
from [clroot].[Material
)
Update cte
set String1 = NewVal
Upvotes: 1