PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > Format Number on Select
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Format Number on Select

Réponse
 
LinkBack Outils de la discussion
Vieux 26/12/2007, 19h30   #1
Erich93063
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Format Number on Select

I have a price field that when I query it, it returns the price as
"5.0000". What function can I use to return the price as "5.00"?

THANKS
  Réponse avec citation
Vieux 26/12/2007, 20h02   #2
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Format Number on Select

Formatting is normally the job of the presentation/reporting layer, where
this is done best.

If the price is numeric then one way is to cast it to the correct decimal
precision (note that rounding will occur):
SELECT CAST(5.0000 AS NUMERIC(10, 2))

If it is character data type, then:
SELECT LEFT('5.0000', LEN('5.0000') - 2),
STUFF('5.0000', LEN('5.0000') - 2, 2, '')

HTH,

Plamen Ratchev
http://www.SQLStudio.com

  Réponse avec citation
Vieux 26/12/2007, 23h00   #3
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Format Number on Select

Erich93063 (erich93063@gmail.com) writes:
> I have a price field that when I query it, it returns the price as
> "5.0000". What function can I use to return the price as "5.00"?


str(). The syntax is str(val[, width[, scale]]) if memory serves. Look it up
in Books Online for the exact details.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
  Réponse avec citation
Vieux 27/12/2007, 13h31   #4
Madhivanan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Format Number on Select

On Dec 27, 12:30am, Erich93063 <erich93...@gmail.com> wrote:
> I have a price field that when I query it, it returns the price as
> "5.0000". What function can I use to return the price as "5.00"?
>
> THANKS


Where do you want to show data?
If you use front end application, use format function there
  Réponse avec citation
Vieux 09/01/2008, 20h16   #5
Knowledgy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Format Number on Select

cast( '5.0000' as decimal(9,2))

--
Sincerely,
John K
Knowledgy Consulting, LLC
knowledgy.org

Atlanta's Business Intelligence and Data Warehouse Experts


"Erich93063" <erich93063@gmail.com> wrote in message
news:5c976abd-e0a0-4f5d-8f02-ac697a516f75@t1g2000pra.googlegroups.com...
>I have a price field that when I query it, it returns the price as
> "5.0000". What function can I use to return the price as "5.00"?
>
> THANKS



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12545 seconds with 13 queries