Working with CTE


There are often situations

 I just want to share an easy example of CTE

Declare @StartIndex AS Int = 100,
@MaximumRows AS int = 200;


with cteCustomers (Row, Email) AS (
Select row_number()  OVER (ORDER BY Email) AS Row, Email

From OrderContact With(NOlock)
Inner Join [Sale] With(NOlock) ON sale.CustomerOrderContactID= OrderContact.ID
WHERE Email != '' AND Email IS NOT NULL
)
--Order By Email ASC


Select * From cteCustomers
WHERE Row >= @StartIndex AND Row <= @MaximumRows

Comments