473,626 Members | 3,325 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.OpenRecordse t("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 28959
rkc

"deko" <dj****@hotmail .com> wrote in message
news:ON******** *********@newss vr29.news.prodi gy.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.OpenRecordse t("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.dabb a.do.rochester. rr.nope> wrote in message
news:fb******** *********@twist er.nyroc.rr.com ...

"deko" <dj****@hotmail .com> wrote in message
news:ON******** *********@newss vr29.news.prodi gy.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.OpenRecordse t("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******@pcdata sheet.com
www.pcdatasheet.com

"rkc" <rk*@yabba.dabb a.do.rochester. rr.nope> wrote in message
news:fb******** *********@twist er.nyroc.rr.com ...

"deko" <dj****@hotmail .com> wrote in message
news:ON******** *********@newss vr29.news.prodi gy.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.OpenRecordse t("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.Am ount = -[Amount]
WHERE tblNegValues.Am ount < 0

--
Hope this helps
Arno R

"deko" <dj****@hotmail .com> schreef in bericht
news:ON******** *********@newss vr29.news.prodi gy.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.OpenRecordse t("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.co m>:
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.t iscali.nl...
Deko,
Why won't a simple update query do the trick for you?

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

--
Hope this helps
Arno R

"deko" <dj****@hotmail .com> schreef in bericht
news:ON******** *********@newss vr29.news.prodi gy.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.OpenRecordse t("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.OpenRecordse t("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******** *********@newss vr29.news.prodi gy.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.OpenRecordse t("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.OpenRecordse t("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

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

Similar topics

2
1924
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. Thanks for help! Dirk Hagemann
2
3703
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 have negative values in the first place? Thx.
2
1599
by: bafidi | last post by:
i write a number to textbox1.text i want to learn if it is negative or positive
1
4802
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 less than operator: int myIndex=myList.BinarySearch( myObject ); if ( myIndex < 0 ) when using the BinarySearch method and in my own experience I see that sometimes it returns other negative values (other than -1).
1
2584
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
1675
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
27381
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
2042
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 convert these values in this way: 6,28 - (value) into positive values. Is there any functions for these operations and how will it look like?
0
8266
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8199
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.