title: When creating a SQL view can i have temp tables?
body: <p>I am using Microsoft SQL -- I need to create a view that pulls a lot of data - about 100 columns, but in order to make it efficient I have to filter the data on 3-5 different joins first. There is no clean way to do this without a few temp tables. But the view doesn't seem to allow me. it Just says "incorrect sytax near 'AS'" </p>
  
  <p>my code looks like this </p>
  
  <pre><code>CREATE VIEW [dbo].[LV_ViewName] AS
  
  declare @table1 table
  (
  customer_no int,
  name varchar(100),
  ...
  )
  </code></pre>
  
  <p>several of those followed</p>
  
  <p>by a </p>
  
  <pre><code>declare #work table
  (
  customer_no int,
  name varchar(100),
  --    all encompasing data
  ...
  )
  </code></pre>