SQL Server - Select - Creating an output with Row Numbers
SQL Server provides a row_number() function.
Here is an example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
with DistinctDescriptions as ( select description from [dbo].[20260427 SacSewer Fleet Information_Collections] g where g.description isnotnull union select description from [dbo].[20260427 SacSewer Fleet Information_Treatment] g where g.description isnotnull ) Select AssetClassID =null, ClassCode='a'+cast(Row_Number() over (orderby description) +100asvarchar(3)) , ClassDesc= description from DistinctDescriptions go