sql >> Base de Datos >  >> RDS >> Sqlserver

necesita usar ROW_NUMBER sin más en sqlserver 2005

Utilice varias cláusulas ROW_NUMBER por columna y elija la pertinente:

....
    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
....

O utilice una expresión CASE. Nota:todos los tipos de datos deben ser compatibles

ROW_NUMBER() OVER (ORDER BY CASE @sort
                     WHEN 1 THEN [Column1]
                     WHEN 1 THEN [Column2]
                     WHEN 1 THEN [Column3]
                     ...
                   END

O Si realmente desea un número de fila arbitrario, haga esto:

ROW_NUMBER() OVER (ORDER BY (SELECT 1)) as rn