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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Convert to currency
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sz1
Aged Yak Warrior

United Kingdom
555 Posts

Posted - 03/26/2012 :  07:35:43  Show Profile  Reply with Quote
I know we can do a for dates.
Convert(varchar, Mydate,100) as 'MyDateFormat'

How do I do the same for money to currency so, to change the below prices to $00.00 format:


StartDate StandardCost ListPrice totalcost Profit
Jul 1 2003 12:00AM 0.8565 2.29 3.1465 1.4335

sz1
Aged Yak Warrior

United Kingdom
555 Posts

Posted - 03/26/2012 :  07:41:27  Show Profile  Reply with Quote
this seemed to work

'$'+Convert(varchar,Convert(money,StandardCost),1)

any better ways please let me know. I know its better to do this in the front end but if a client needs a quick export this is handy to copy straight to Excel.
Go to Top of Page

sz1
Aged Yak Warrior

United Kingdom
555 Posts

Posted - 03/26/2012 :  07:56:34  Show Profile  Reply with Quote
How do I do the same for this including a SUM
So,

'£' Convert(varchar, Convert(money(SUM(ListPrice + StandardCost),1)) as totalcost,

?

Thanks
Go to Top of Page

sz1
Aged Yak Warrior

United Kingdom
555 Posts

Posted - 03/26/2012 :  11:05:13  Show Profile  Reply with Quote
Sorted it, you dont need the SUM function.

Use AdventureWorks
Go

Select Convert(varchar,SellStartDate,100) as 'StartDate', -- convert to date format
'£' + Convert(varchar,Convert(money,StandardCost),1) as StandardCost, -- convert to currency
'£' + Convert(varchar,Convert(money,ListPrice),1) as ListPrice,
'£' + Convert(varchar,Convert(money,ListPrice + StandardCost),1) as totalcost,
'£' + Convert(varchar,Convert(money,ListPrice - StandardCost),1) as Profit
from Production.Product
Where StandardCost >0

Group by ListPrice, StandardCost, SellStartDate
Order by StandardCost

RESULT

StartDate StandardCost ListPrice totalcost Profit
Jul 1 2003 12:00AM £0.86 £2.29 £3.15 £1.43
Jun 1 1998 12:00AM £1,059.31 £1,431.50 £2,490.81 £372.19
Jul 1 2003 12:00AM £1,082.51 £1,700.99 £2,783.50 £618.48
Jul 1 2002 12:00AM £1,251.98 £2,294.99 £3,546.97 £1,043.01
Jul 1 2002 12:00AM £1,265.62 £2,319.99 £3,585.61 £1,054.37
Jul 1 2003 12:00AM £1,481.94 £2,384.07 £3,866.01 £902.13

Edited by - sz1 on 03/26/2012 11:35:52
Go to Top of Page

maryjohnson
Starting Member

USA
3 Posts

Posted - 04/26/2012 :  08:48:44  Show Profile  Reply with Quote
for details of all currency please visit,,
http://www.currency.com.pk/uae-gold-rate-dubai-exchange-rate.html
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000