jc524400


I am trying to format the result output from my query so that it looks like currency. Does anyone know how to do this

Here is my very simple select statement:

SELECT Field_Value

FROM tbl_all_results

I was thinking some kind of cast/convert would do the trick but I can't seem to get anything to work.

Thanks for your help!




Re: Output Format Question

MarcD


Generally formatting such as this should actually be done in your presentation layer. E.g. your application's Data Grid, report viewer etc.There are a million hacks to do it in SQL all depending upon what you want to use. There's also the money data type.

SELECT '$ ' + CAST(CAST(NumericID AS numeric(18, 2)) AS VARCHAR(10)) AS expr1
FROM Deutsche_Brokers





Re: Output Format Question

Manivannan.D.Sekaran

jc524400 wrote:

I am trying to format the result output from my query so that it looks like currency. Does anyone know how to do this

What exactly you need here. Are you trying to attach the currency symbol ($1000.00)

Give few sample output.







Re: Output Format Question

jc524400

Here are a few examples of what I get today when I run the query and what I want to get.

Current Results Format What I would like to get

5000.00 $5,000.00

17839.23 $17,839.23

54894634.89 $54,894,634.89

21675874271.78 $21,675,874,271.78

Thanks in advance for your help!!!





Re: Output Format Question

Arnie Rowland

Use the CONVERT() function.

Refer to Books Online, Topic: 'Cast and Convert'

declare @MyValue money
set @MyValue = 21675874271.78


select ( '$' + convert( varchar(20), @MyValue, 1 ))

---------------------
$21,675,874,271.78