Dr.Abdulwahab Al-anesi
asked on
Correction of odd number to even number
A rounded calculated field in my query is retuning odd number in some records, I want it to increase the number by one to be even number.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why the 2 minuses?
Basically the same as mine
Basically the same as mine
That's what makes it round up, nice trick. INT by itself rounds down.
Round should be avoided for critical purposes as it is known to be buggy:
http://www.xbeat.net/vbspeed/c_Round.htm
Also, INT is native to SQL, thus much faster.
If this matters in this case we don't know ...
/gustav
Round should be avoided for critical purposes as it is known to be buggy:
http://www.xbeat.net/vbspeed/c_Round.htm
Also, INT is native to SQL, thus much faster.
If this matters in this case we don't know ...
/gustav
Create an update query that selects the fields that is odd and add 1 to it. See attached test query that works
updatequery.jpg
updatequery.jpg
In that case you should use CLNG
= -CLNG(-(Field1) / 2) * 2
= -CLNG(-(Field1) / 2) * 2
That won't work. CLng rounds 0.5+ up for odd integers.
Also, CLng is VBA thus (marginally) slower than INT.
/gustav
Also, CLng is VBA thus (marginally) slower than INT.
/gustav
Int might not be big enough..
I'd go for
=ROUND(Field1/2,0)*2
or
=CLNG(Field1/2)*2
I'd go for
=ROUND(Field1/2,0)*2
or
=CLNG(Field1/2)*2
It is "enough" whatever that means as is performs the rounding 100% correctly for any numeric value which Access can handle.
What may not be enough are the other suggestions as explained earlier.
The exception is peakpeak's suggestion:
If (Num Mod 2) = 1 Then Num = Num + 1
but that is a bit long-winded. For SQL it would read:
IIF(Num Mod 2 = 1, Num + 1, Num)
/gustav
What may not be enough are the other suggestions as explained earlier.
The exception is peakpeak's suggestion:
If (Num Mod 2) = 1 Then Num = Num + 1
but that is a bit long-winded. For SQL it would read:
IIF(Num Mod 2 = 1, Num + 1, Num)
/gustav
update table
set field = field + 1
where field MOD 2 = 1
set field = field + 1
where field MOD 2 = 1
If you want to replace all odd numbers to even numbers then: [number] + ([number] mod 2) should do the job
In access' query builder you can put: "EvenNumber: [number]+([number] Mod 2)" in the field criteria where [number] is the (calculated) field/parameter (EventNumber is the name given to the output field)
In access' query builder you can put: "EvenNumber: [number]+([number] Mod 2)" in the field criteria where [number] is the (calculated) field/parameter (EventNumber is the name given to the output field)
Saved in hotmail ??
Points should be split
ASKER