title: 'Create VIEW' must be the only statement in the batch
body: <p>I have the following SQL:</p>
  
  <pre><code>    ALTER PROCEDURE [dbo].[usp_gettasks]  
      @ID varchar(50)
  
      AS
       declare @PDate Date
  
  
       WHILE (DATEPART(DW, @PDate) =  1 OR DATEPART(DW, @PDate) =  7 )
       BEGIN
  
        set @PDate =  DATEADD(day, 1, @PDate)
  
       END
  
       CREATE VIEW tblList AS
  
       select tt.ItemOrder,tt.DisplayVal,  DATEADD(day, tt.DaysDue, @PDate)  from tblLine tt
       where tt.ID = 1 
  </code></pre>
  
  <p>I get the following message: </p>
  
  <blockquote>
    <p>Incorrect syntax: 'Create VIEW' must be the only statement in the batch</p>
  </blockquote>
  
  <p>I tried putting <code>GO</code> before <code>Create View</code>, but then it can't recognize the value of <code>PDate</code>.</p>