Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2015 10:47
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 anonymous/d131d9f6c7bfa68d1385 to your computer and use it in GitHub Desktop.
Save anonymous/d131d9f6c7bfa68d1385 to your computer and use it in GitHub Desktop.
IF OBJECT_ID('tempdb..#rowCountTB') IS NOT NULL
DROP TABLE #rowCountTB;
WITH DistinctTable
AS (
SELECT DISTINCT [fieldValue]
FROM [tableName]
)
,RowNumber
AS (
SELECT ROW_NUMBER() OVER (
ORDER BY [fieldValue]
) AS RowNum
,[fieldValue]
FROM DistinctTable
)
SELECT *
INTO #rowCountTB
FROM RowNumber
ORDER BY [fieldValue]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment