title: Oracle SQL LAG Function
body: <p>I'd appreciate some help with this code, I'm getting a 'missing keyword' error. I've never used the Lag function before, so hopefully I using it correctly. Thanks for your help. Gav</p>
  
  <pre><code>CREATE VIEW GS_Date AS
  SELECT                        
          DATE_DATE, 
          DATE_FLAG,
          CASE WHEN  LAG ( DATE_FLAG)  OVER ( ORDER BY DATE_DATE ) = '1' THEN DATE_STEP = ( LAG ( DATE_FLAG)  OVER ( ORDER BY DATE_DATE ) ) + '1'
                   WHEN  LAG ( DATE_FLAG)  OVER ( ORDER BY DATE_DATE ) = '0' AND LAG ( DATE_FLAG)  OVER ( ORDER BY DATE_DATE ) =  '-1'  THEN DATE_STEP = ( LAG ( DATE_FLAG)  OVER ( ORDER BY DATE_DATE ) ) + '1'
                   ELSE DATE_STEP = LAG ( DATE_FLAG)  OVER ( ORDER BY DATE_DATE )  END AS DATE_STEP
  FROM DATE_GROUP                  
  </code></pre>