Saturday, January 20, 2018

Create View with CTE - i.e. with as clause



Normal way of creating a view is..

create[alter] view myViewWithoutCTE as (
select * from ...)


Create view with CTE ...notice brackets use.

create[alter] view myViewWithoutCTE as
with
cte1 as (select * from),
cte2 as (select * from),
cte3 as (select * from)
select * from cte's



Notice the brackets () in red causes error when using CTE

No comments:

Post a Comment

Recently Executed queries

 SELECT     txt.TEXT AS [SQL Statement],     qs.EXECUTION_COUNT [No. Times Executed],     qs.LAST_EXECUTION_TIME AS [Last Time Executed],   ...