SQL Server dense_rank() on nvarchar column -


from this question, possible use dense_rank on nvarchar column?

here's sql fiddle created nvarchar column, see results yourself, , here's one column int

of course possible. examples quite different. in first, values ordered as:

1 11 2 3 4 5 

in second this:

1 2 3 4 5 11 

hence, results different. numbers stored strings treated strings, not numbers.

edit:

there 2 ways "treat nvarchar()" number. first conversion, such as:

dense_rank() on (order cast(number decimal)) grp 

(or whatever type want).

the second work if values integers , not have leading zeros:

dense_rank() on (order len(number), number) grp 

Popular posts from this blog

html/hta mutiple file in audio player -

debugging - Reference - What does this error mean in PHP? -