Alphanumeric Sort
Ich benötige schnelle Hilfe beim Sortieren von Daten auf der SQL-Seite. Ich benutzeSqlserver 2012
(gut wenn Antwort mit der neuen Funktion geben).
Ich suche bereits einige Links als Alphanumerische Sortierung , Alphanumerische Zeichenfolge Sortierung in SQL Server - Code-Projekt. Gibt aber nicht das gewünschte Ergebnis.
Noch was ich probiert habe:
CREATE TABLE dbo.Section
(
Section varchar(50) NULL
)
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsit no.43')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsit no.41')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 11')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 1')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 12')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 2')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 3')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 4')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 40')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 41')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite no.20')
INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite no.41')
INSERT INTO dbo.Section (Section.Section) VALUES ('Cabin')
INSERT INTO dbo.Section (Section.Section) VALUES ('Group Tent Campsite')
INSERT INTO dbo.Section (Section.Section) VALUES ('Tent Campsite')
INSERT INTO dbo.Section (Section.Section) VALUES ('test1')
INSERT INTO dbo.Section (Section.Section) VALUES ('test2')
INSERT INTO dbo.Section (Section.Section) VALUES ('test11')
SELECT Section
FROM dbo.Section
--Show normal Sort
SELECT Section
FROM dbo.Section
ORDER BY Section
--Show AlphaNumberic Sort
SELECT Section
FROM dbo.Section
ORDER BY LEFT(Section,PATINDEX('%[0-9]%',Section)), -- alphabetical sort
CONVERT(varchar(50),SUBSTRING(Section,PATINDEX('%[0-9]%',Section),LEN(Section))) -- numerical sort
--cleanup our work
--DROP Table dbo.Section
Jetzt was ich will ist:wenn die gleiche Zeichenfolge zuerst in alphabetischer Reihenfolge und dann in numerischer Reihenfolge gefunden wird (berücksichtigen Sie auch das Leerzeichen, wenn möglich, oder geben Sie das Ergebnis ohne Leerzeichen an, wie Camping Nr. 41 und Camping Nr. 41 dies in derselben Reihenfolge tun)
Actual Result Expected Result
Campsit no.41 Campsit no.41
Campsit no.43 Campsit no.43
Campsite No. 1 Campsite No. 1
Campsite No. 11 Campsite No. 2
Campsite No. 12 Campsite No. 3
Campsite No. 2 Campsite No. 4
Campsite No. 21 Campsite No. 11
Campsite No. 3 Campsite No. 12
Campsite No. 4 Campsite No. 21
Campsite No. 40 Campsite No. 40
Campsite No. 41 Campsite No. 41
Campsite no.20 Campsite no.20 --this will good to come here, if possible or if not, then remove space and set approriate
Campsite no.41 Campsite no.41 --this will good to come here, if possible or if not, then remove space and set approriate
Group Tent Campsite Group Tent Campsite
Tent Campsite Tent Campsite
test1 test1
test11 test2
test2 test11