Search code examples
t-sqlsql-server-2008common-table-expressionsql-view

Select into a view


I have a simple CTE x and I wish to select its contents into a view. Can you select into a view using the same type of syntax that you can for a table? i.e.

SELECT * 
INTO newTable
FROM OldTable

Can new views be created dynamically like this?


Solution

  • create view myView
    AS
    with x
    as
    (select 1 as num)
    select * from x