gpt4 book ai didi

sql-server - LAG 不是可识别的内置函数名称

转载 作者:行者123 更新时间:2023-12-02 16:16:16 24 4
gpt4 key购买 nike

我有一个创建以下存储过程的脚本:

CREATE PROCEDURE [dbo].[GetDurationFree] 
@EquipmentName varchar(50)
AS
UPDATE dbo.EquipmentMessages
SET UnlockDuration = (SELECT DATEDIFF (SECOND,
(SELECT TOP 1 LAG(TimeUnlock) OVER (ORDER BY TimeUnlock) TimeUnlock
FROM dbo.EquipmentMessages
WHERE EquipmentName = @EquipmentName
ORDER BY TimeLock DESC),
(SELECT TOP 1 TimeLock FROM dbo.EquipmentMessages
WHERE EquipmentName = @EquipmentName
ORDER BY TimeLock DESC)))
WHERE TimeLock = (SELECT MAX(TimeLock) FROM dbo.EquipmentMessages
WHERE EquipmentName = @EquipmentName);

唯一的问题是它使用了滞后,当我尝试执行它时出现以下错误:

Msg 195, Level 15, State 10, Procedure GetDurationFree, Line 6
'LAG' is not a recognized built-in function name.

Msg 156, Level 15, State 1, Procedure GetDurationFree, Line 12
Incorrect syntax near the keyword 'ORDER'.

我在网上阅读,有人提出了以下建议:

ALTER DATABASE yourDBName
SET COMPATIBILITY_LEVEL = 110

但是当我运行这个时,我收到以下错误:

Msg 15048, Level 16, State 1, Line 1
Valid values of the database compatibility level are 80, 90, or 100.

我正在运行

SQL Server 2014 Management Studio Express 版本

但是当我输入以下SELECT @@version

我明白了:

Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64) 
Mar 29 2009 10:11:52
Copyright (c) 1988-2008 Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

最佳答案

我最终所做的是进入控制面板的卸载程序并删除与 SQL 相关的所有内容。然后我重新安装了该程序,它运行良好。

我注意到计算机上有一个未安装的 2008 早期版本。也许问题就出在这里。

关于sql-server - LAG 不是可识别的内置函数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38338569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com