|
This looks like an ugly problem to deal with in SQL, but I think it'sjust
possible. Rather than trying to come up with a different solution, I
altered yours slightly. See if it works for all cases.have
with prob01a as
(select replace(field04, '$', '') as money from prob01) select
money, case money when ' ' then 0 else
case when position('-' IN money) > 0 then
decimal(replace(money,'-',''),9,2) * -1
else
decimal(money,9,2,'.') end end
FROM prob01a
Hth, Elvis
Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com
-----Original Message-----
Subject: Re: SQL String to numeric conversion
Afternoon all
I took some of the responses answering the original request because I
somewhat of the same problem.field
I have a file (PROB01) containing the following data in a particular
(Field04)the
Field04
$
$302.54
3.66
1.54-
33.60-
$ 11.21-
2.22
.34
$ .36
$11
Using the following sql statement
with prob01a as
(select replace(field04, '$', '') as money from prob01)
select money, case money when ' ' then 0 else
decimal(money,9,2,'.') end
FROM prob01a
I get the following results
MONEY CASE expression
.00
.00
302.54 302.54
3.66 3.66
1.54- +++++++++++++
33.60- +++++++++++++
11.21- +++++++++++++
2.22 2.22
.34 .34
.36 .36
11 11.00
as you can see the problem I am having is with the minus sign, and for
life of me I just cannot seem to come up with the correct solution tolist
satisfy all conditions
Anyone any ideas?
Alan Shore
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.