Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Am New To SQL SERVER And Usaaly I Stored Select Query Result In VIEW But Recently
I figured Out We Can Also Store Our Query Result with `WITH` Clause So Waht is The Practical Difference Between

CREATE VIEW AS `SQL SELECT QUERY`

AND

WITH (Comman Table Expression)
AS
`SQL SELECT QUERY`

And When Should We Use Which One
Posted

A view is something store in SQL server. A cte exists only in a procedure, and in fact can only be used once. Ctes also support recursion, which views do not. A view is used to create a commonly used view. A cte is used for the benefit of readability in a single block of sql.
 
Share this answer
 
Comments
Nisarg Desai 1-Jan-14 5:28am    
so you mean view`s are stored result permanently and CTE`s Are Stored Result Temporary
did I got right?
Christian Graus 1-Jan-14 5:33am    
Not the result. The view itself is stored for reuse through the db. The cte is local to a proc, and in fact, local to the next statement in the proc. You can't define a cte at the top of a proc and reference it again at the bottom, even.
Nisarg Desai 1-Jan-14 5:37am    
Okay Alright I Got It . Thanks Man. Thanks For Help
 
Share this answer
 
Comments
Nisarg Desai 2-Jan-14 1:27am    
Thanks Nishant

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900