
Years(Yr) AS (SELECT TOP 2000+N-1 FROM iTally) ITally(N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) FROM 元 a, 元 b),

WITH - Create CTE tally table with 1,000,000 rows

IF OBJECT_ID('tempdb.#Sales') IS NOT NULL DROP TABLE #Sales ĬREATE TABLE #Sales - using global temp table so it's available after the proc executes IF OBJECT_ID('dbo.GenerateSalesData') IS NOT NULL DROP PROC dbo.GenerateSalesData ĬREATE PROC int, - something to int, - records per partition int - the lower this number, the more possible ties

The great thing about helping people on forums is how you often find yourself learning more than the person(s) you are helping. With SQL Server 2012+ it’s easy because you have the PERCENT_RANK rank distribution function, but on pre-2012 systems a little more work is required. I was recently helping someone on a SQL forum calculate the percentile rank in SQL Server 2008.
