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
 Function that format money

Author  Topic 

h2sut
Starting Member

40 Posts

Posted - 2008-10-15 : 15:57:30
I a column of salary in this format 4500.00 an 198723.00 etc...


is there a way to format it to $4,500 and $198,723 etc...

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-15 : 16:03:54
Yes. See CONVERT function in Books Online.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-10-15 : 16:31:32
Take a look at the code I posted on this thread>
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=111225

CODO ERGO SUM
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-15 : 17:13:29
Why not format it on your front end and let your db keep the datatypes. As when formated to currency values, you cant do any calculations or other formatting with them
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-16 : 01:49:07
Adding to afrika, there are functions available at your front end applications to easily do the formatting as above.
Go to Top of Page

h2sut
Starting Member

40 Posts

Posted - 2008-10-16 : 18:12:16
Okay you stated there are functions to do this. What are the functions that can do this?
Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2008-10-17 : 00:53:51
try

Select '$' + Convert (varchar(50), yourcolumnName, 106) as yourcolumnName from yourTableName. QED :)

check out my blog at http://www.aqauriumlore.blogspot.com
Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2008-10-17 : 00:55:37
Forgot to say, it only been tested in MSSQL 2005.

Sample results when I used the above query in my table.

Select '$' + Convert (varchar(50), LocalAmount, 106) as Disbursment from dbo.Disbursement


$100,000.00
$18,000.00
$100,000.00
$200,000.00
$4,000.00

Hope this is what you want.

check out my blog at http://www.aqauriumlore.blogspot.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-17 : 04:23:38
quote:
Originally posted by h2sut

Okay you stated there are functions to do this. What are the functions that can do this?


which is your front end application ?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-10-17 : 09:45:59
quote:
Originally posted by EugeneLim11

Forgot to say, it only been tested in MSSQL 2005.

Sample results when I used the above query in my table.

Select '$' + Convert (varchar(50), LocalAmount, 106) as Disbursment from dbo.Disbursement


$100,000.00
$18,000.00
$100,000.00
$200,000.00
$4,000.00

Hope this is what you want.

check out my blog at http://www.aqauriumlore.blogspot.com



This is a bad idea if you can avoid it; those values are not numeric, they are VARCHAR, and they no longer compare or sort properly. You should always return raw, clean, properly-typed data from your database and handle all formatting at your presentation layer, unless for some reason you have no other option.

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

- Advertisement -