snippetMajor
Transact SQL using WITH in CREATE VIEW
Viewed 0 times
createsqlwithviewusingtransact
Problem
I want to create VIEW using WITH clauses, but really can't find any references on correct syntax.
I want smth like this
And what is the correct syntax for using several WITH clauses?
Nothing useful on MSDN :(
I want smth like this
WITH TempTbl AS (SELECT ...)
CREATE VIEW SomeView
SELECT *
FROM TempTblAnd what is the correct syntax for using several WITH clauses?
Nothing useful on MSDN :(
Solution
The CTE goes inside the view.
Take a query with a CTE
Just add CREATE VIEW AS .. GO
MSDN does describe multiple CTEs (See example j)
Take a query with a CTE
WITH cte AS (...) SELECT ...;Just add CREATE VIEW AS .. GO
CREATE VIEW
AS
WITH cte AS (...) SELECT ...;
GOMSDN does describe multiple CTEs (See example j)
CREATE VIEW
AS
WITH
cte1 AS (...),
cte2 AS (...),
cte3 AS (...)
SELECT ...
GOCode Snippets
WITH cte AS (...) SELECT ...;CREATE VIEW
AS
WITH cte AS (...) SELECT ...;
GOCREATE VIEW
AS
WITH
cte1 AS (...),
cte2 AS (...),
cte3 AS (...)
SELECT ...
GOContext
StackExchange Database Administrators Q#7239, answer score: 29
Revisions (0)
No revisions yet.