Använd flera ROW_NUMBER satser per kolumn och välj den relevanta:
....
ROW_NUMBER() OVER (ORDER BY [Column1]) as rn1,
ROW_NUMBER() OVER (ORDER BY [Column2]) as rn2,
ROW_NUMBER() OVER (ORDER BY [Column3]) as rn3,
ROW_NUMBER() OVER (ORDER BY [Column4]) as rn4
....
ELLER använd ett CASE-uttryck. Obs:alla datatyper måste vara kompatibla
ROW_NUMBER() OVER (ORDER BY CASE @sort
WHEN 1 THEN [Column1]
WHEN 1 THEN [Column2]
WHEN 1 THEN [Column3]
...
END
ELLER Om du verkligen vill ha ett godtyckligt radnummer gör du så här:
ROW_NUMBER() OVER (ORDER BY (SELECT 1)) as rn