Order for 1.99.10 and server 1.99.9 sql

Sorry for my mistake, I have to provide a real sample for the question, the symbols inside are included in my identifier:

code example:

select ID from student order by ID Expected output from mine but system output ------------------------- ----------------- JAD.1.99.9 JAD.1.99.10 JAD.1.99.10 JAD.1.99.9 

and this ID is of type nvarchar .

+6
source share
2 answers

Yesterday there was a similar question where I found out that you can use hierarchyid to sort versions (if you use at least SQL-Server 2008):

 SELECT id FROM student ORDER BY Cast('/' + Replace(id, '.', '/') + '/' AS HIERARCHYID) 

Demo

+14
source

You need to order the substring of the part after any point. This will be a specific SQL query, and since you did not specify which one you are using, I cannot provide a detailed SQL example.

Here is how you can use decimal values

http://www.w3resource.com/sql/aggregate-functions/avg-decimal-places-using-cast-within-avg.php

The answer from Tim is the best.

But I give one more solution for varchar order values ​​-

 SELECT id FROM student ORDER BY ID desc 
-2
source

Source: https://habr.com/ru/post/945250/


All Articles