Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Urutkan Peluru di Database

WITH T(YourColumn) AS
(
SELECT '1' UNION ALL
SELECT '2' UNION ALL
SELECT '1.1.11' UNION ALL
SELECT '4.1' UNION ALL
SELECT '5' UNION ALL
SELECT '2.1' UNION ALL
SELECT '1.1' UNION ALL
SELECT '4' UNION ALL
SELECT '1.2.1' UNION ALL
SELECT '4.2.2' UNION ALL
SELECT '4.3' UNION ALL
SELECT '4.2' UNION ALL
SELECT '4.3.1' UNION ALL
SELECT '4.2.1' UNION ALL
SELECT '11.2' UNION ALL
SELECT '1.2.4' UNION ALL
SELECT '4.4'
)
SELECT *
FROM T 
ORDER BY CAST('/' + YourColumn + '/' AS HIERARCHYID)

Kembali

YourColumn
----------
1
1.1
1.1.11
1.2.1
1.2.4
2
2.1
4
4.1
4.2
4.2.1
4.2.2
4.3
4.3.1
4.4
5
11.2

Apakah itu yang Anda butuhkan?




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara menghapus 1000 baris teratas dari tabel menggunakan Sql Server 2008?

  2. Mempertahankan ORDER BY di SELECT INTO

  3. Cara Menghapus File di SQL Server 2019

  4. Bagaimana cara mengambil desimal saat membulatkan rata-rata dalam SQL

  5. Mendapatkan izin eksekusi ke xp_cmdshell