Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Foramtting

Author  Topic 

jhon11
Starting Member

42 Posts

Posted - 2007-11-16 : 12:58:15
Hi,
In my query

select AVG(totalpaid) as 'avg cost/30 days(physican)',

from test

Now Basically in that column i am getting COST..and I want to add
$ sign before that...and also I want to restrict my o/p with only 3 Decimal.

current result
123.100129
444.237800
666.423878

Desierd o/p
$123.100
$444.237
$666.423

Thank you

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-11-16 : 13:03:04
restricting decimal can be done by doing a CONVERT(decimal(10,3), XXXX). The $ sign should, I think, be added at the front end.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jhon11
Starting Member

42 Posts

Posted - 2007-11-16 : 13:09:59
I am getting following error..by doing that stuff.


Error converting data type varchar to numeric.
Go to Top of Page

jhon11
Starting Member

42 Posts

Posted - 2007-11-16 : 13:12:43
in ur giving suggestion...

where its CONVERT( decimal(10,3), XXXX)

Wht should i put??

Should I put CONVERT(decimal(10,3),totalpaid)
or
Should I put CONVERT( decimal(10,3),'avg cost/30 days(physican)')
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-11-16 : 14:15:05
Formatting is not something that should be done in T-SQL; you should format your results at your presentation layer -- i.e., wherever you are ultimately displaying the results, such as on a report, a web page, Excel, windows app, etc. Just return raw data from your database.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -