Format Number on Select

Format Number on Select

am 26.12.2007 20:30:24 von erich93063

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

Re: Format Number on Select

am 26.12.2007 21:02:42 von Plamen Ratchev

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

Re: Format Number on Select

am 27.12.2007 00:00:24 von Erland Sommarskog

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/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx

Re: Format Number on Select

am 27.12.2007 14:31:48 von Madhivanan

On Dec 27, 12:30=A0am, Erich93063 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

Re: Format Number on Select

am 09.01.2008 21:16:12 von Knowledgy

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

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

Atlanta's Business Intelligence and Data Warehouse Experts


"Erich93063" wrote in message
news:5c976abd-e0a0-4f5d-8f02-ac697a516f75@t1g2000pra.googleg roups.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