LAG is not a recognized built in function name
<p>I have a script that creates the following stored procedure : </p>

<pre><code>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);
</code></pre>

<p>The only problem is that It uses a Lag, when I try to execute it I get the following errors : </p>

<blockquote>
  <p>Msg 195, Level 15, State 10, Procedure GetDurationFree, Line 6<br>
  'LAG' is not a recognized built-in function name.</p>
  
  <p>Msg 156, Level 15, State 1, Procedure GetDurationFree, Line 12<br>
  Incorrect syntax near the keyword 'ORDER'.</p>
</blockquote>

<p>I was reading online and someone suggested the following :</p>

<pre><code>ALTER DATABASE yourDBName
SET COMPATIBILITY_LEVEL = 110
</code></pre>

<p>However when I run this, I get the following error :</p>

<blockquote>
  <p>Msg 15048, Level 16, State 1, Line 1<br>
  Valid values of the database compatibility level are 80, 90, or 100.</p>
</blockquote>

<p>I am running </p>

<p>SQL Server 2014 Management Studio, the express version</p>

<p>However when I enter the following  <code>SELECT @@version</code></p>

<p>I get : </p>

<pre><code>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 &lt;X64&gt; (Build 7601: Service Pack 1)
</code></pre>