Thomas stand ja kürzlich vor dem Problem, eine CTE hierarchisch korrekt ausgeben zu wollen, was ihn zu Niels Berglund führte (Sorting Hierarchical CTE's).
Allerdings blieb ein Problem: Die Daten sind nun zwar hierarchisch sortiert - nicht jedoch alphabetisch innerhalb der Hierarchie.
Heute stand ich schließlich vor dem gleichen Problem - und ich glaube, ich habe eine Lösung gefunden ;-)
Ausgehend von einer Tabelle Kategorien, welche die Felder Name (nvarchar), ID (uniqueidentifier) und Parent (uniqueidentifier) besitzt, sollen also die Kategorien hierarchisch und alphabetisch dargestellt werden:
Korrekt wäre also z.B.:
| Name |
ID |
Parent |
| Rohre und Formteile |
C55C8856-6205-4F76-A15A-6FCD4A68A831 |
00000000-0000-0000-0000-000000000000 |
| Geschweißte Rohre und Formteile |
9EEE0951-4E63-4494-BB18-88BCC1D4A3E5 |
C55C8856-6205-4F76-A15A-6FCD4A68A831 |
| Rohrbögen geschweißt |
8A137449-6108-47D2-8ED0-AE0EA4176EB2 |
9EEE0951-4E63-4494-BB18-88BCC1D4A3E5 |
| Rohre geschweißt |
085A0AA3-AB9D-4DD1-9739-77040E627445 |
9EEE0951-4E63-4494-BB18-88BCC1D4A3E5 |
Erhalten habe ich mit Niels' Lösung jedoch nur:
| Name |
ID |
Parent |
| Rohre und Formteile |
C55C8856-6205-4F76-A15A-6FCD4A68A831 |
00000000-0000-0000-0000-000000000000 |
| Geschweißte Rohre und Formteile |
9EEE0951-4E63-4494-BB18-88BCC1D4A3E5 |
C55C8856-6205-4F76-A15A-6FCD4A68A831 |
| Rohre geschweißt |
085A0AA3-AB9D-4DD1-9739-77040E627445 |
9EEE0951-4E63-4494-BB18-88BCC1D4A3E5 |
| Rohrbögen geschweißt |
8A137449-6108-47D2-8ED0-AE0EA4176EB2 |
9EEE0951-4E63-4494-BB18-88BCC1D4A3E5 |
Nach einigem Experimentieren mit Views u.ä. bin ich auf folgende Lösung gekommen:
WITH CTE([Name], ID, ordercol, Parent)
AS
(
SELECT [Name], ID, cast([Name] as varbinary(100)) ordercol, Parent
FROM ProductCategory
WHERE Parent= '{00000000-0000-0000-0000-000000000000}'
UNION ALL
SELECT ProductCategory.[Name],
ProductCategory.ID,
cast(ordercol + CAST(ProductCategory.[Name] AS BINARY(4)) as varbinary(100)) ordercol,
ProductCategory.Parent
FROM ProductCategory INNER JOIN
CTE ON ProductCategory.Parent =
CTE.ID
)
SELECT [Name], ID, Parent
FROM CTE
ORDER BY ordercol, [Name]
Damit erhielt ich o.g. gewünschtes hierarchisch und alphabetisch korrekt sortiertes Resultat. Außerdem funktioniert jetzt sogar die Änderung von ORDER BY auf [Name] DESC.
Currently rated 1.3 by 51 people
- Currently 1.27451/5 Stars.
- 1
- 2
- 3
- 4
- 5
SqlPrompt (aktuell noch Beta) ist ein Windows-Tool, das sich im Systray einnistet und von dort aus SQL-Intellisense für folgende Editoren bietet:
- Query Analyzer (2000)
- Enterprise Manager (2000)
- Sql Server Management Studio (2005)
- Visual Studio .NET 2003
- Visual Studio 2005
- Ultra Edit
- EditPlus 2
SqlPrompt im Query Analyzer in Action:

Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Bereits wenige Monate nach dem Erscheinen von SQL Server 2005 ist nun das Service Pack 1 zum Download verfügbar.
Um die Express Editions zu aktualisieren, müssen die aktualisierten Versionen mit SP1 heruntergeladen und installiert werden.
Hierbei gibt es jetzt außerdem zusätzlich zum Download mit normalem Funktionsumfang auch eine Version mit Reporting Services und Volltextsuche zum Download.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Microsoft hat einen neuen Coding-Contest gestartet: "Made in Express". Wichtigstes Kriterium: die eingereichte Idee muß mit den Express Editions der .NET 2.0 Werkzeuge erstellt sein.
Details zum Contest gibt es bei S. 'Soma' Somasegar und auf der Contest-Website.
Currently rated 2.1 by 9 people
- Currently 2.111111/5 Stars.
- 1
- 2
- 3
- 4
- 5
Kent Tegels zeigt in seinem Blog, wie man die
AdventureWorks Datenbank unter SQL Server Express installiert.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
"SQL Server Express, a free product based on SQL Server 2005 technology, includes the unique Application XCopy feature, and networking and security that differ from other SQL Server 2005 editions. These topics and the integration of SQL Server Express with Visual Studio 2005 are discussed. Compare this product with the existing Microsoft free databases like MSDE and Jet. (20 printed pages)"
SQL Server 2005 Express Edition Overview
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5