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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to format currency

Author  Topic 

nt4vn
Yak Posting Veteran

98 Posts

Posted - 2009-02-27 : 10:20:03
Hello:

I want to format this statement to show AvgRtn in currency:
sum(am_collections)/count(distinct dt_pd_acct_begin) as AvgRtn

right now it came out like: 781.18750000000000000000000

Thanks,

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-02-27 : 10:36:29
What do you want your output to look like?
Go to Top of Page

nt4vn
Yak Posting Veteran

98 Posts

Posted - 2009-02-27 : 10:40:32
I want it show like $781.19
Thanks,

quote:
Originally posted by vijayisonly

What do you want your output to look like?



Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-02-27 : 10:57:03
Try this.

SELECT '$' + CONVERT(CHAR,CAST(ROUND(AvgRtn,2) AS DECIMAL (10,2)))
Go to Top of Page

nt4vn
Yak Posting Veteran

98 Posts

Posted - 2009-02-27 : 11:21:58
It's exactly what I am looking for.

Thanks so much!


quote:
Originally posted by vijayisonly

Try this.

SELECT '$' + CONVERT(CHAR,CAST(ROUND(AvgRtn,2) AS DECIMAL (10,2)))

Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-02-27 : 11:26:35
Welcome
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-02 : 03:32:25
quote:
Originally posted by nt4vn

I want it show like $781.19
Thanks,

quote:
Originally posted by vijayisonly

What do you want your output to look like?






If you use front end application, do the formation there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-02 : 10:26:01
and you've lots of currency formatting functions available at front end application to do this
Go to Top of Page

nt4vn
Yak Posting Veteran

98 Posts

Posted - 2009-03-03 : 08:48:40
Yes, you are right. I could not sum the amount when I export data to excel. How would I correct the format in sql transaction to make it work in Excel.

Thanks,


quote:
Originally posted by visakh16

and you've lots of currency formatting functions available at front end application to do this

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-03 : 08:57:42
for changing format in sql, you've to convert it to varchar which will cause problems when you use currency value for comparison, sorting,...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-03 : 09:00:10
quote:
Originally posted by nt4vn

Yes, you are right. I could not sum the amount when I export data to excel. How would I correct the format in sql transaction to make it work in Excel.

Thanks,


quote:
Originally posted by visakh16

and you've lots of currency formatting functions available at front end application to do this




If you export data to EXCEL, format data there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nt4vn
Yak Posting Veteran

98 Posts

Posted - 2009-03-03 : 09:19:17
quote:
Originally posted by madhivanan

quote:
Originally posted by nt4vn

Yes, you are right. I could not sum the amount when I export data to excel. How would I correct the format in sql transaction to make it work in Excel.

Thanks,


quote:
Originally posted by visakh16

and you've lots of currency formatting functions available at front end application to do this




If you export data to EXCEL, format data there

Madhivanan

Failing to plan is Planning to fail



Yes I got it work now by exporting all to excel. Thanks All!
Go to Top of Page
   

- Advertisement -