Discussion in 'OT Technology' started by jasuklee, Jun 23, 2003.
gotta convert a string that would be like this
into an int like this
how do you do that??
SQL server? MySQL? Access? Oracle? what platform? and is the $99.00 in a string format or currency or what?
Try forcing it without any modifications - I know access doesn't care.
you can't physically convert, but in your SELECT clause, you can perform a scalar function against it. But yeah, answer SLED, then we can find out exactly how that value is stored.
Well, I'd personally strip the $ off the front and do atoi if it were in C++ or C# (I believe C# has the same command?)
Depends really on how you're using it.
I think we'd all like to buy a clue...
You inserting or pulling this out as a select? What flavor database you working with?
Assuming its a string and you're trying to trim it down to in int via MySQL SELECT, you'll need to read up on SUBSTRING and LOCATE. You'll need to do a substring to eliminate the '$', and then one more to grab the left half of the decimal (use LOCATE to figure out where in the string is the '.', then your substring can lock on to that and return you the first chunk). For MySQL string functions: http://www.mysql.com/doc/en/String_functions.html
Your mileage may vary between various DB engines. You could also use regular expressions from within MySQL if I remember correctly (REGEX() - powerful and with the right regular expression could pull out what you need, although you may take a small performance hit for it)
Typically, DB engines are not all that quick when it comes to string fiddling and I'd recommend formating the string via your outside code (be it C/C++/Java/ASP/PHP/etc).
SUBSTR and LOCATE functions also work well when you want to rearrange a persons name if the format is LAST FIRST and you want to show as FIRST LAST
I think the whole point is it depends on the database engine being used. And chances are, this guy has long since moved on from the problem!
uhhhh ... you could CAST or CONVERT (I'm not sure which offhand) in MSSQL ...
both work in mssql actually
yes but to achieve the proper datatype AND formatting, would they both still work?
the only difference between the two functions is that convert() has different date formatting.... i believe