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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping out specific characters

Status
Not open for further replies.

pixiesfb

Programmer
Apr 27, 2001
62
US
I have a column in a database with data like this:

$22.25
$443.93
$2.50

I would like to run a query to strip the dollar signs to get this:

22.25
443.93
2.50

Thanks!

 
use the numberformat() function. something like numberformat(FIELD,"00.00")
Chandler
I ran over my dogma with karma!
 
A more general approach will also work. The Replace function can be used to replace any substring in a string with any other substring. In our case, you would replace the '$' with the null string:

Code:
<cfset newValue = Replace( value, &quot;$&quot;, &quot;&quot;, &quot;ALL&quot; )>

You don't need the &quot;ALL&quot; since you know that there is exactly one occurrence of the dollar sign.

Mike
 
Replace(YourColumn,'$','','all') would do it in your CFML template output although if you can be sure that all your columns have a precedding '$' you could try doing it right in the SQL.

SELECT
Right(YourColumn,(len(YourColumn) - 1)) AS NoDollars

Scalar functions can be much faster than thier CFML counterparts.

 
Maybe I'm overlooking something, here, but is there any particular reason you have to store the number with a $? Why not just store it in the database as a decimal number and use the DollarFormat function when you want to display it? Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top