Skip to content

Instantly share code, notes, and snippets.

@ksummerlin
Created June 28, 2012 17:26
Show Gist options
  • Save ksummerlin/3012676 to your computer and use it in GitHub Desktop.
Save ksummerlin/3012676 to your computer and use it in GitHub Desktop.
--@max_other_orders is a parameter to stored proc
select top (@max_other_orders)
OH.SalesOrderID,
OH.CustomerId,
OH.SalesOrderNumber,
OH.Status,
count(*) over(partition by OH.CustomerId) as OtherOrdersCount
from Sales.SalesOrderHeader OH
where
OH.CustomerID = @customer_id
and OH.SalesOrderID <> @current_sales_id
order by OH.OrderDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment