473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to make all negative values positive?

Is there an easy way to make all negative values positive in a particular
table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?
Nov 12 '05 #1
12 28939
rkc

"deko" <dj****@hotmail.com> wrote in message
news:ON*****************@newssvr29.news.prodigy.co m...
Is there an easy way to make all negative values positive in a particular
table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?


The Abs function?

Nov 12 '05 #2
I'll bet Abs is more efficient than multiplication and subtraction, but I
still need a way to apply this to an entire table. Should I use For Each?
Must I use a Recordset operation here?

Thanks!

"rkc" <rk*@yabba.dabba.do.rochester.rr.nope> wrote in message
news:fb*****************@twister.nyroc.rr.com...

"deko" <dj****@hotmail.com> wrote in message
news:ON*****************@newssvr29.news.prodigy.co m...
Is there an easy way to make all negative values positive in a particular table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?


The Abs function?


Nov 12 '05 #3
Use an update query that only contains the Amount field. Put this expression
where it says Update To:
IIF([Amount] < 0,[Amount]*-1,[Amount])
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com

"rkc" <rk*@yabba.dabba.do.rochester.rr.nope> wrote in message
news:fb*****************@twister.nyroc.rr.com...

"deko" <dj****@hotmail.com> wrote in message
news:ON*****************@newssvr29.news.prodigy.co m...
Is there an easy way to make all negative values positive in a particular
table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?


The Abs function?


Nov 12 '05 #4
Deko,
Why won't a simple update query do the trick for you?

UPDATE tblNegValues SET tblNegValues.Amount = -[Amount]
WHERE tblNegValues.Amount < 0

--
Hope this helps
Arno R

"deko" <dj****@hotmail.com> schreef in bericht
news:ON*****************@newssvr29.news.prodigy.co m...
Is there an easy way to make all negative values positive in a particular
table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?

Nov 12 '05 #5
dj****@hotmail.com (deko) wrote in
<Tz****************@newssvr29.news.prodigy.com>:
I'll bet Abs is more efficient than multiplication and
subtraction, but I still need a way to apply this to an entire
table. Should I use For Each? Must I use a Recordset operation
here?


If you're changing all the values in a column in a table, or a
subset of values that match certain criteria, SQL is definitely the
way to go. Arno has given you one such solution.

A SQL UPDATE is almost always going to be faster than walking
through a recordset and changing one row at a time, though there
are some kinds of changes that can't really be done with SQL, so
you sometimes do need to walk a recordset. But it's not nearly as
often as many people think (especially people who come from an
xBase environment).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #6
Thanks for the reply.

You're right - an update query is the way to go. "Amount = -Amount" is
simple enough, and works great. I was focusing too much on the arithmetic
operations I thought were necessary to convert the negative to a positive
and didn't think I could do it with SQL.

I think Abs is a good way to go, too (rck's suggestion).

UPDATE tblNegValues SET Amount = Abs(Amount) WHERE Amount < 0
"Arno R" <ar****************@tiscali.nl> wrote in message
news:3f**********************@dreader2.news.tiscal i.nl...
Deko,
Why won't a simple update query do the trick for you?

UPDATE tblNegValues SET tblNegValues.Amount = -[Amount]
WHERE tblNegValues.Amount < 0

--
Hope this helps
Arno R

"deko" <dj****@hotmail.com> schreef in bericht
news:ON*****************@newssvr29.news.prodigy.co m...
Is there an easy way to make all negative values positive in a particular table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?


Nov 12 '05 #7
"deko" <dj****@hotmail.com> wrote in news:ONjHb.2907$NJ7.1857
@newssvr29.news.prodigy.com:
Is there an easy way to make all negative values positive in a particular
table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?


I suppose (whimsically), that you are storing a calculated field if you do
this, and that you should leave your data as it is, and simply use and/or
display the absolute value of these values.
--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #8
hi,

update MyTable
Set Amount=(Amount*-1)
where Amount <0
"deko" <dj****@hotmail.com> schrieb im Newsbeitrag
news:ON*****************@newssvr29.news.prodigy.co m...
Is there an easy way to make all negative values positive in a particular
table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?

Nov 12 '05 #9
Actually, it's part of an import process that downloads bank statements and
populates a table with all the various transactions. The database then
crunches the numbers, which need to be all positive values. But the
different banks are not consistent in how they represent the amounts - some
are negative (2,483.39), some are positive $2,483.39.

This seems to do the trick:

UPDATE tblTransactions SET Amount = Abs(Amount) WHERE Amount < 0

Thanks to all who replied - I appreciate the help!
"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...
"deko" <dj****@hotmail.com> wrote in news:ONjHb.2907$NJ7.1857
@newssvr29.news.prodigy.com:
Is there an easy way to make all negative values positive in a particular table?

I've been experimenting with this:

Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("tblNegValues")

Do
If rst!Amount < 0 Then rst!Amount = rst!Amount - (rst!Amount * 2)
Loop

Is there a better way?


I suppose (whimsically), that you are storing a calculated field if you do
this, and that you should leave your data as it is, and simply use and/or
display the absolute value of these values.
--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)

Nov 12 '05 #10
hi
I just made a little query to do the job and this is the SQL code it
generated

UPDATE t_BANK_LINE SET t_BANK_LINE.BKL_EXPENSE = Abs([BKL_EXPENSE]);

it change all values of BKL_EXPENSE to positive . .

in code you could use

DoCmd.RunSql "UPDATE t_BANK_LINE SET t_BANK_LINE.BKL_EXPENSE =
Abs([BKL_EXPENSE]);"

there is no test for positive or negative numbers . . as the result is ALL
positive

cheers
paul g


"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:94***************************@24.168.128.78.. .
dj****@hotmail.com (deko) wrote in
<Tz****************@newssvr29.news.prodigy.com>:
I'll bet Abs is more efficient than multiplication and
subtraction, but I still need a way to apply this to an entire
table. Should I use For Each? Must I use a Recordset operation
here?


If you're changing all the values in a column in a table, or a
subset of values that match certain criteria, SQL is definitely the
way to go. Arno has given you one such solution.

A SQL UPDATE is almost always going to be faster than walking
through a recordset and changing one row at a time, though there
are some kinds of changes that can't really be done with SQL, so
you sometimes do need to walk a recordset. But it's not nearly as
often as many people think (especially people who come from an
xBase environment).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Nov 12 '05 #11
"Kinetic - Paul G" <ki*****@alwaysonline.net.au> wrote in
news:3f******@alwaysonline.net.au:
hi
I just made a little query to do the job and this is the SQL
code it generated

UPDATE t_BANK_LINE SET t_BANK_LINE.BKL_EXPENSE =
Abs([BKL_EXPENSE]);

it change all values of BKL_EXPENSE to positive . .

in code you could use

DoCmd.RunSql "UPDATE t_BANK_LINE SET t_BANK_LINE.BKL_EXPENSE
= Abs([BKL_EXPENSE]);"

there is no test for positive or negative numbers . . as the
result is ALL positive

cheers
paul g


This is true, however, it is bad practice to update a record that's
not changing. There may be locking issues, some rdbms may timestamp
the records, Etc.

There is also the issue of performance in large tables where
updating two million records to fix a problem with two hundred
records imposes a serious load on the server.

Just my two cents worth.

Bob Q
Nov 12 '05 #12

"Bob Quintal" <bq******@generation.net> wrote in message
news:67******************************@news.teranew s.com...
"Kinetic - Paul G" <ki*****@alwaysonline.net.au> wrote in
news:3f******@alwaysonline.net.au:
hi
I just made a little query to do the job and this is the SQL
code it generated

UPDATE t_BANK_LINE SET t_BANK_LINE.BKL_EXPENSE =
Abs([BKL_EXPENSE]);

it change all values of BKL_EXPENSE to positive . .

in code you could use

DoCmd.RunSql "UPDATE t_BANK_LINE SET t_BANK_LINE.BKL_EXPENSE
= Abs([BKL_EXPENSE]);"

there is no test for positive or negative numbers . . as the
result is ALL positive

cheers
paul g


This is true, however, it is bad practice to update a record that's
not changing. There may be locking issues, some rdbms may timestamp
the records, Etc.

There is also the issue of performance in large tables where
updating two million records to fix a problem with two hundred
records imposes a serious load on the server.

Just my two cents worth.

Bob Q


Good points Bob . .. I'll keep them in mind . . cheers paul g


Nov 12 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dirk Hagemann | last post by:
Hi, Is there a datatype in python which allows no negative values? I subtract several times something from a value and I don't want to chek everytime if this value is still bigger or equal 0. ...
2
by: luke | last post by:
Could anyone, please, explain to me why I have negative values in RowModCtr column in sysobjects table? I have tested that after I update statistics the RowModCtr column is reset to 0. But why do I...
2
by: bafidi | last post by:
i write a number to textbox1.text i want to learn if it is negative or positive
1
by: illegal.prime | last post by:
So I see from the documentation here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemCollectionsArrayListClassBinarySearchTopic.asp That the code uses the...
1
by: Badis | last post by:
Hi guys, I have a negative values in my Amount column in GridView could U tell me how to display them with no (-) sign in front, knowing that my gridview is bounded to a DataView. Thanks
1
by: Badis | last post by:
Hi guys, I have a negative values in my Amount column in GridView could U tell me how to display them with no (-) sign in front, knowing that my gridview is bounded to a DataView. Thanks
3
by: vimal | last post by:
hi all, i am new to python guys. hope u will help me with this.... i have a list of numbers say a = how should i check for negative values in the list
4
by: bengevik | last post by:
I need to multiplicate all the values in a coloumn with a constant and returning them in a (eventually new) column. My second problem is that there are negative values in some rows. I need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.