Führende Nullen einfügen

SELECT RIGHT(CONCAT('000000',13000),6)

Wenn eine Zeitangabe als Integer Wert gespeichert wird, so verliert es die führenden Nullen (z.B. 1:30 => 013000 =>13000). Um die führenden Null hinzuzufügen können wir den obere Code Snippet verwenden. Danach ist es möglich diesen Wert in den entsprechenden Zeit Datentyp zu casten.

-- for postgres
SELECT RIGHT(CONCAT('000000',13000),6)::time
-- MSSQL needs the additional colon
SELECT CAST(STUFF(STUFF(RIGHT(CONCAT('000000', 13000) ,6),3,0,':'),6,0,':') as time )

Schreibe einen Kommentar

Your email address will not be published. Required fields are marked *

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny

hungsblog | Nguyen Hung Manh | Dresden
Nach oben scrollen