Recursive Queries Using Common Table Expressions (CTE)

Introduction

Common Table Expression(CTE) creates a temporary result set within the defined execution scope. Recursive means repeating itself until condition not satisfied. A CTE can be used to create a recursive query.

Details

CTE can be used in SELECT, INSERT, UPDATE, DELETE and CREATE VIEW statement.

WITH Orders_CTE([OrderID],[CustomerID],[EmployeeID],[OrderDate],[RequiredDate],[ShippedDate])
AS
(
	SELECT [OrderID],[CustomerID],[EmployeeID],[OrderDate],[RequiredDate],[ShippedDate]
	FROM [Northwind].[dbo].[Orders]
)
SELECT * FROM Orders_CTE

Comments

Email
Print