title: SQL Server: trying to create view inside a stored procedure
body: <p>I'm trying to create my view inside the stored procedure but I faced an error . </p>
  
  <p>My code is :</p>
  
  <pre><code>    alter PROCEDURE p.Azmoon1 
      AS
      begin
         EXEC ('IF OBJECT_ID (''r.r_Sales01_Requests__Duplicates'', ''V'') IS NOT NULL
              DROP VIEW r.r_Sales01_Requests__Duplicates ;
              go
              create view r.r_Sales01_Requests__Duplicates ( 
               CompanyID
              ,Branch
              ,Year
              ,VoucherType,VoucherNumber
              ,Date_Persian
              ,Row
          ) as
          select 
               CompanyID
              ,Branch
              ,Year
              ,VoucherType,VoucherNumber
              ,Date_Persian
              ,Row
          from t_SalesRequests
          group by CompanyID,Branch,Year,VoucherType,VoucherNumber,Date_Persian,Row
          having count(*)&gt;1
  
          go
  
      ')
      end
  </code></pre>
  
  <p>When I call my procedure like below :</p>
  
  <pre><code>execute p.Azmoon1 
  </code></pre>
  
  <p>I got these errors:</p>
  
  <blockquote>
    <p>Incorrect syntax near 'go'<br>
    'CREATE VIEW' must be the first statement in a query batch.<br>
    Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).</p>
  </blockquote>