title: Create TSQL view from function with DECLARE variables not working
body: <p>I can easily create a SQL view from a function using the code below.</p>
  <pre><code>IF EXISTS(SELECT * FROM [sys].[objects] WHERE object_id = object_id('InvoicedItemsView') AND OBJECTPROPERTY(object_id,'IsView')=1)
  DROP VIEW [dbo].[InvoicedItemsView]
  GO
  CREATE VIEW [dbo].[InvoicedItemsView]
  AS
      SELECT * FROM sp_GetInvoicedItems('201803', '201803', '201803', '201803',NULL,NULL) AS InvoicedItems 
  GO
  
  /* SELECT all data from the created view */
  SELECT *
  FROM [dbo].[InvoicedItemsView]
  GO
  </code></pre>
  <p>HOWEVER, why can I not create a View with DECLARED variables for the function??
  The below code causes TSQL to have several error messages thrown.</p>
  <pre><code>IF EXISTS(SELECT * FROM [sys].[objects] WHERE object_id = object_id('InvoicedItemsView') AND OBJECTPROPERTY(object_id,'IsView')=1)
  DROP VIEW [dbo].[InvoicedItemsView]
  GO
  CREATE VIEW [dbo].[InvoicedItemsView]
  AS
      DECLARE @P0 AS CHAR (6) = '201803', @P1 AS NVARCHAR (6) = '201803', @P2 AS CHAR (6) = '201803', @P3 AS NVARCHAR (6) = '201803', @P4 AS INT = NULL, @P5 AS NVARCHAR (4000) = NULL;
      SELECT * FROM sp_GetInvoicedItems(@P0, @P1, @P2, @P3, NULL,NULL) AS InvoicedItems 
  GO
  
  /* SELECT all data from the created view */
  SELECT *
  FROM [dbo].[InvoicedItemsView]
  GO
  </code></pre>