Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

FORMAT in SQL

Empfohlene Antworten

Hallo! :)

Ich mal wieder.

Ich möchte gerne eine Kommazahl (z.B. 1,2000) mit nur einer Kommastelle (1,2) ausgeben.

Gibt es da (wie in VB) einen "Format"-Befehl?

Finde dazu leider nix.

OK, wenn's keine explizite Funktion dazu gibt, dann werd ich das benutzen:

[FONT="Courier New"][COLOR="Blue"]DECLARE[/COLOR] @Value [COLOR="blue"]AS DECIMAL[/COLOR] (10, 4)


[COLOR="blue"]SET[/COLOR] @Value = 1.2000


[COLOR="blue"]PRINT[/COLOR] [COLOR="Red"]'Die Zahl (auf eine Stelle hinterm Komma): '[/COLOR] +

[COLOR="Magenta"]STUFF[/COLOR]([COLOR="magenta"]CONVERT[/COLOR]( [COLOR="blue"]VARCHAR[/COLOR](10) , @Value), [COLOR="Magenta"]CHARINDEX[/COLOR]('.', @Value) + 2, 3, [COLOR="Red"]''[/COLOR])[/FONT]

Naja, hatte gedacht, dass es vielleicht weniger "kompliziert" geht, trotzdem Danke! :D

wie Darth_Zeus schon schreibt, ohne angabe der DB schon schwer,

aber schau mal nach ROUND(zahl, NKS)

gruss

Hätte klappen können mit ROUND(), aber die Zahl soll nicht gerundet sondern einfach nur auf eine Nachkommastelle gekürzt werden.

Wir reden hier übrigens vom SQL Server 2005. :)

Du kannst deine Variable natuerlich auch einfach einer anderen Variablen vom Typ DECIMAL (10, 1) zuweisen. Dann hast auch eine Nachkommastelle, der Rest wird gerundet.

Ach und pass bei deinem DECIMAL (10, 4) auch auf, dass du keine groesseren Zahlen als 999999,9999 verwendest ;)

Goos

@ Goos

Danke! Das funktioniert! :D

[FONT="Courier New"]DECLARE @Message AS VARCHAR(100)

DECLARE @Value  AS DECIMAL(10, 4)


SET @Value = 0.25


SET @Message = 'Auf alle Artikel ' +

              CONVERT(VARCHAR(10), FLOOR(@Value * 100))

              + '% Rabatt!'


PRINT @Message[/FONT]

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.