Skip to content

Instantly share code, notes, and snippets.

@mhayes
Created December 21, 2010 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhayes/750394 to your computer and use it in GitHub Desktop.
Save mhayes/750394 to your computer and use it in GitHub Desktop.
Common table expression usage in SQL Server
USE AdventureWorks2008;
WITH ShippingTime(OrderDate,ShipDate,DaysToShip) AS
(
SELECT OrderDate, ShipDate,DATEDIFF(day,OrderDate,ShipDate)
FROM Sales.SalesOrderHeader
)
SELECT *
FROM ShippingTime;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment