提问人:D.j. Black 提问时间:10/28/2023 最后编辑:marc_sD.j. Black 更新时间:10/29/2023 访问量:40
如何在更新 SQL 命令中使用 Lead
How to use Lead in Update SQL command
问:
这适用于:SELECT
(LEAD(AltCode,2) OVER (ORDER BY AltCode) ) from [clroot].[Material]
但不适用于 Update
USE [MEKON-EPE]
UPDATE [clroot].Material
SET String1 = (LEAD(AltCode, 2) OVER (ORDER BY AltCode))
FROM [clroot].[Material]
我收到此错误:
消息 4108,级别 15,状态 1,第 6
行 窗口化函数只能出现在 SELECT 或 ORDER BY 子句中。
我想使用接下来 2 列的值更新特定列。
答:
1赞
John Cappelletti
10/29/2023
#1
只是为了扩展我的评论
with cte as (
Select *
,NewVal = LEAD(AltCode,2) OVER (ORDER BY AltCode)
from [clroot].[Material
)
Update cte
set String1 = NewVal
评论
VIEW