Question Locked

Access query math

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can anyone help me with the syntax of an access query that would subract 1 from the number contained with in a field?

For example, if I have a field that has the number 15 in it, I want to run a query that will subract 1 from that number. Thanks.

7 replies

by shellbot

SELECT Table1.Number1, ([number1])-1 AS Result
FROM Table1;

This gives you 2 columns, the field with the number, and the second one your result

by jiminpa

Automatically write the resulting number back or is there something else I will then need to do?

You said it gives me two columns? Does it create an additional column with the result?

As you can probably tell I am not overly SQL savvy. :)

by maevinn

Select statements don't alter the data within the column, they just display information. In the sample code, it will display the initial value, and that value less 1.

You need an Update statement to actually alter the value.

UPDATE Table1 SET Table1.Junk = [junk]-1

Using a where statement to target the update to the specified records.

If you're using Access, you don't have to write the SQL statement though--pick the column you want, select UPDATE as the query type, and in the Criteria column, enter [ColumnName] - 1

by shellbot

Wasn't as thorough as I should have been :(

Are you wanting to:
1. leave the original column as is, and have a second column the original column - 1
or
2. do you want to permanetly minus 1 from all numbers in that column?
or
3. are you just tryin gto display the result of the calculation?

by jiminpa

I got pull on another project and didn't get a chance to play with it until now. I was able to take what you guys said and make my code do what it needed to do.

B-)

This discussion is closed to new replies.