SQL Formatter (leider nur bis SSMS 2019)

Beim Lesen von T-SQL im SSMS fehlt immer wieder eine Formatierungs-Hilfe.
Praktisch fand ich:
Quelle/n (des gleichen Entwicklers):
https://github.com/TaoK/PoorMansTSqlFormatter
Ist GitHub, aber nur schwierig die richtige *.msi zu finden
http://architectshack.com/PoorMansTSqlFormatter.ashx#Download_15
Hier muss man die „Extension for CURRENT VERSION of SSMS….“ suchen und kann die PoorMansTSqlFormatterSSMSPackage.Setup.1.6.16.msi laden und installieren.

Ggf. ist noch das .NET Framework 2.0 nötig:
Download .NET 2.0 SP1 (x64) from Official Microsoft Download Center

Das SSMS muss ggf. neu gestartet werden und dann ist im Menü „Tools“ der Punkt „Format T-SQL Code“

Benutzung:
Den SQL Code, den man in einer Query hat, kann man dann über den o.g. Punkt den Code neu formatiert anzeigen lassen. Typisch ist das nötig, wenn man komplexe Stored Procedure in einer einzigen Zeile findet.

Sollte man eine Fehlermeldung sehen:
---------------------------
Microsoft SQL Server Management Studio
---------------------------
The 'FormatterPackage' package did not load correctly.

The problem may have been caused by a configuration change or by the installation of another extension.
You can get more information by examining the file
‚C:\Users\frank.odenbreit\AppData\Roaming\Microsoft\AppEnv\14.0\ActivityLog.xml‘.

Restarting Visual Studio could help resolve this issue.

Continue to show this error message?
—————————
Ja Nein
—————————

Lösung:
https://github.com/TaoK/PoorMansTSqlFormatter/issues/187
EINFACH DEN DIALOG MIT „NO“ bzw. „NEIN“ BESTÄTIGEN!!!!
Siehe d. o.g. Link:

Don't bother reading all that text - I messed up the installer during the split at the start of the week.
The problem will have been temporary (as long as you say "No" in the error dialog, the extension loads fine on next SSMS restart and forever after), but still, almost 300 downloads of the bad installer... :(
Fixed installer is live, downloadable at http://architectshack.com/PoorMansTSqlFormatter.ashx
Sorry about the inconvenience.

In einzelnen Fällen war das Menü deaktiviert („grau“). In dem Fall hat mir dieser Link geholfen die Konfiguration des SSMS anzupassen („ssms.exe.config“):

https://stackoverflow.com/questions/63313632/poor-mans-t-sql-formatting-add-in-format-t-sql-code-option-disabled-in-sql-ser

 

SQL: Zahlen in lokalem Format

Problem Darstellung eines Ergebnisses per T-SQL möchte man gelegentlich unterschiedlich formatieren.
Speziell bei „Datum“ und „Zahlen“ hat man ständig mit Problemen.
Beispiel im SQL hat man ständig Werte wie „9999.99 aber im deutschem Excel wird nicht als 9.999,99“ verstanden und muss ständig mit hohem Zeitaufwand im Excel als „Text“ eingelesen und dann werden bei den betroffenen Spalten erst Punkt in Komma gewandelt und dann müsse die Spalten in die richtige Formate gebracht werden.
Bei DATUM lässt sich das in einer T-SQL Abfrage mit einem einfachen „SET“-Kommando anpassen. Leider gibt’s bisher keine einfache Lösung bei Microsoft.
Daher hilft möglicherweise der „FORMAT“-Befehl…

SELECT
    -- c => currency
    -- n => numeric
    FORMAT(987654321, N'N', C.culture) AS some_number
,   FORMAT(987654321, N'c', C.culture) AS some_currency
,   C.culture
FROM
    (
        -- Language culture names
        -- http://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx
        VALUES
            ('en-US')
        ,   ('en-GB')
        ,   ('de-DE')
    ) C (culture);

Select FORMAT(987654321, N'N', 'de-DE') AS some_number

Quelle: https://stackoverflow.com/questions/4377352/how-do-i-format-a-number-with-commas-in-t-sql