問題描述
我有一個創建以下存儲過程的腳本:
I have a script that creates the following stored procedure :
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);
唯一的問題是它使用了延遲,當我嘗試執行它時出現以下錯誤:
The only problem is that It uses a Lag, when I try to execute it I get the following errors :
消息 195,級別 15,狀態 10,過程 GetDurationFree,第 6 行
LAG"不是可識別的內置函數名稱.
Msg 195, Level 15, State 10, Procedure GetDurationFree, Line 6
'LAG' is not a recognized built-in function name.
消息 156,級別 15,狀態 1,過程 GetDurationFree,第 12 行
關鍵字ORDER"附近的語法不正確.
Msg 156, Level 15, State 1, Procedure GetDurationFree, Line 12
Incorrect syntax near the keyword 'ORDER'.
我在網上閱讀,有人提出以下建議:
I was reading online and someone suggested the following :
ALTER DATABASE yourDBName
SET COMPATIBILITY_LEVEL = 110
但是,當我運行它時,出現以下錯誤:
However when I run this, I get the following error :
消息 15048,級別 16,狀態 1,第 1 行
數據庫兼容級別的有效值為 80、90 或 100.
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,快速版
SQL Server 2014 Management Studio, the express version
但是當我輸入以下 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 相關的內容.然后我重新安裝了程序,它運行良好.
What I ended up doing is going into the control panel under uninstall a program and deleted everything that has to do with SQL. Then I re installed the program and It worked fine.
我注意到計算機上沒有安裝 2008 的早期版本.也許問題出在那里.
I noticed that there a early version of 2008 on the computer that wasn't installed. Maybe the problem comes from there.
這篇關于LAG 不是公認的內置函數名稱的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!