Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting INT to a dollar amount 2

Status
Not open for further replies.

KingRichard3

Programmer
Feb 9, 2005
58
US
Is there an easy way to convert
a double: 1234.56
to this: $1,234.56
?

Thanks,
Rick
 
Ok, I did as you suggested. I started with my date table. I Create a new table with data in the date table converted to money (to save me time).

Using James's method, the query took 4.8 seconds.
Code:
SELECT 	'$' + CONVERT(varchar(20), CAST(Amount AS money), 1)

Using the UDF method, the query took 49.2 Seconds.
Code:
Select	dbo.FormatNumber(Amount, 1, '$') From TempNumeric

I'll bet on a 6 to 1 speed difference in this case.

Looks more like a 10 to 1 speed improvement.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
A star for your efforts...thanks George. I'm starting to get a feel for UDF damages! I was pretty sure the string manipulation would be especially nasty.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top