how do I increment a field
Posted in 2005
A newcomer asked how to add 1 to every odd value in a column so all values become even, having only worked out how to spot odds by dividing by 2. Several respondents pointed to the MOD function, and the poster confirmed the working solution: UPDATE <table> SET <field> = <field> + 1 WHERE ABS(MOD(<field>, 2)) = 1 — the ABS handling negative values. Problem resolved; a short, straightforward thread.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: General Discussion
I am trying to increment by 1 all odd numbers in a list, so that all the numbers end of being even. I can get my list by dividing by 2, but then how do I take the ??.5 entries and add 1 to each of them. =20
update <table> set <field> = <field> + 1 where abs (mod (<field>, 2)) = 1; that should do the trick. ----- Original Message ----- From: "Hulock, Mar...." <mhulock@sric.net> To: <ids@iiug.org> Sent: Thursday, July 28, 2005 9:53 AM Subject: how do I increment a field [5506] > I am trying to increment by 1 all odd numbers in a list, so that all the > numbers end of being even. I can get my list by dividing by 2, but then > how do I take the ??.5 entries and add 1 to each of them. > > =20 > > > >
Not
sure I understand the question.
Have you tried:
update table set column=column+1 where mod(column,2=1);
Although I can't remember if mod is an operator.
j.
----- Original Message -----
From: "Hulock, Mar...." <mhulock@sric.net>
To: <ids@iiug.org>
Sent: Thursday, July 28, 2005 10:53 AM
Subject: how do I increment a field [5506]
> I am trying to increment by 1 all odd numbers in a list, so that all the
> numbers end of being even. I can get my list by dividing by 2, but then
> how do I take the ??.5 entries and add 1 to each of them.
>
> =20
>
>
>
Is this in an UPDATE statement? A SELECT? An SPL procedure? What? Art S. Kagel ----- Original Message ----- From: Mar.... Hulock <mhulock@sric.net> At: 7/28 12:53 I am trying to increment by 1 all odd numbers in a list, so that all the numbers end of being even. I can get my list by dividing by 2, but then how do I take the ??.5 entries and add 1 to each of them. =20
--0__=09BBFADFDFF38CC08f9e8a93df938690918c09BBFADFDFF38CC0 Content-type: multipart/alternative; Boundary="1__=09BBFADFDFF38CC08f9e8a93df938690918c09BBFADFDFF38CC0" --1__=09BBFADFDFF38CC08f9e8a93df938690918c09BBFADFDFF38CC0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: quoted-printable set col =3D col+1 where mod(col,2) =3D 1; = "Hulock, Mar...." = <mhulock@sric.net = > = To Sent by: ids@iiug.org = forum.subscriber@ = cc iiug.org = Subj= ect how do I increment a field [5506= ] 07/28/2005 09:53 = AM = = = = = I am trying to increment by 1 all odd numbers in a list, so that all th= e numbers end of being even. I can get my list by dividing by 2, but the= n how do I take the ??.5 entries and add 1 to each of them. =3D20 = --1__=09BBFADFDFF38CC08f9e8a93df938690918c09BBFADFDFF38CC0 Content-type: text/html; charset=US-ASCII Content-Disposition: inline Content-transfer-encoding: quoted-printable <html><body> <p>set col =3D col+1 where mod(col,2) =3D 1;<br> <br> <img src=3D"cid:10__=3D09BBFADFDFF38CC08f9e8a93df938@us.ibm.com" width=3D= "16" height=3D"16" alt=3D"Inactive hide details for "Hulock, Mar..= .." <mhulock@sric.net>">"Hulock, Mar...." <mhul= ock@sric.net><br> <br> <br> <table width=3D"100%" border=3D"0" cellspacing=3D"0" cellpadding=3D"0">= <tr valign=3D"top"><td style=3D"background-image:url(cid:20__=3D09BBFAD= FDFF38CC08f9e8a93df938@us.ibm.com); background-repeat: no-repeat; " wid= th=3D"40%"> <ul> <ul> <ul> <ul><b><font size=3D"2">"Hulock, Mar...." <mhulock@sric.ne= t></font></b><font size=3D"2"> </font><br> <font size=3D"2">Sent by: forum.subscriber@iiug.org</font> <p><font size=3D"2">07/28/2005 09:53 AM</font></ul> </ul> </ul> </ul> </td><td width=3D"60%"> <table width=3D"100%" border=3D"0" cellspacing=3D"0" cellpadding=3D"0">= <tr valign=3D"top"><td width=3D"1%" valign=3D"middle"><img src=3D"cid:3= 0__=3D09BBFADFDFF38CC08f9e8a93df938@us.ibm.com" border=3D"0" height=3D"= 1" width=3D"58" alt=3D""><br> <div align=3D"right"><font size=3D"2">To</font></div></td><td width=3D"= 100%"><img src=3D"cid:30__=3D09BBFADFDFF38CC08f9e8a93df938@us.ibm.com" = border=3D"0" height=3D"1" width=3D"1" alt=3D""><br> <font size=3D"2">ids@iiug.org</font></td></tr> <tr valign=3D"top"><td width=3D"1%" valign=3D"middle"><img src=3D"cid:3= 0__=3D09BBFADFDFF38CC08f9e8a93df938@us.ibm.com" border=3D"0" height=3D"= 1" width=3D"58" alt=3D""><br> <div align=3D"right"><font size=3D"2">cc</font></div></td><td width=3D"= 100%"><img src=3D"cid:30__=3D09BBFADFDFF38CC08f9e8a93df938@us.ibm.com" = border=3D"0" height=3D"1" width=3D"1" alt=3D""><br> </td></tr> <tr valign=3D"top"><td width=3D"1%" valign=3D"middle"><img src=3D"cid:3= 0__=3D09BBFADFDFF38CC08f9e8a93df938@us.ibm.com" border=3D"0" height=3D"= 1" width=3D"58" alt=3D""><br> <div align=3D"right"><font size=3D"2">Subject</font></div></td><td widt= h=3D"100%"><img src=3D"cid:30__=3D09BBFADFDFF38CC08f9e8a93df938@us.ibm.= com" border=3D"0" height=3D"1" width=3D"1" alt=3D""><br> <font size=3D"2">how do I increment a field [5506]</font></td></tr> </table> <table border=3D"0" cellspacing=3D"0" cellpadding=3D"0"> <tr valign=3D"top"><td width=3D"58"><img src=3D"cid:30__=3D09BBFADFDFF3= 8CC08f9e8a93df938@us.ibm.com" border=3D"0" height=3D"1" width=3D"1" alt= =3D""></td><td width=3D"336"><img src=3D"cid:30__=3D09BBFADFDFF38CC08f9= e8a93df938@us.ibm.com" border=3D"0" height=3D"1" width=3D"1" alt=3D""><= /td></tr> </table> </td></tr> </table> <br> <tt>I am trying to increment by 1 all odd numbers in a list, so that al= l the<br> numbers end of being even. I can get my list by dividing by 2, bu= t then<br> how do I take the ??.5 entries and add 1 to each of them.<br> <br> =3D20<br> <br> <br> <br> </tt><br> </body></html>= --1__=09BBFADFDFF38CC08f9e8a93df938690918c09BBFADFDFF38CC0-- --0__=09BBFADFDFF38CC08f9e8a93df938690918c09BBFADFDFF38CC0 Content-type: image/gif; name="graycol.gif" Content-Disposition: inline; filename="graycol.gif" Content-ID: <10__=09BBFADFDFF38CC08f9e8a93df938@us.ibm.com> Content-transfer-encoding: base64 R0lGODlhEAAQAKECAMzMzAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIXlI+py+0PopwxUbpu ZRfKZ2zgSJbmSRYAIf4fT3B0aW1pemVkIGJ5IFVsZWFkIFNtYXJ0U2F2ZXIhAAA7 --0__=09BBFADFDFF38CC08f9e8a93df938690918c09BBFADFDFF38CC0 Content-type: image/gif; name="pic30583.gif" Content-Disposition: inline; filename="pic30583.gif" Content-ID: <20__=09BBFADFDFF38CC08f9e8a93df938@us.ibm.com> Content-transfer-encoding: base64 R0lGODlhWABDALP/AAAAAK04Qf79/o+Gm7WuwlNObwoJFCsoSMDAwGFsmIuezf///wAAAAAAAAAA AAAAACH5BAEAAAgALAAAAABYAEMAQAT/EMlJq704682770RiFMRinqggEUNSHIchG0BCfHhOjAuh EDeUqTASLCbBhQrhG7xis2j0lssNDopE4jfIJhDaggI8YB1sZeZgLVA9YVCpnGagVjV171aRVrYR RghXcAGFhoUETwYxcXNyADJ3GlcSKGAwLwllVC1vjIUHBWsFilKQdI8GA5IcpApeJQt8L09lmgkH LZikoU5wjqcyAMMFrJIDPAKvCFletKSev1HBw8KrxtjZ2tvc3d5VyKtCKW3jfz4uMKmq3xu4N0nK BVoJQmx2LGVOmrqNjjJf2hHAQo/eDwJGTKhQMcgQEEAnEjFS98+RnW3smGkZU6ncCWav/4wYOnAI TihRL/4FEwbp28BXMMcoscQCVxlepL4IGDSCyJyVQOu0o7CjmLN50OZlqWmyFy5/6yBBuji0AxFR M00oQAqNIstqI6qKHUsWRAEAvagsmfUEAImyxgbmUpJk3IklNUtJOUAVLoUr1+wqDGTE4zk+T6FG uQb3SizBCwatiiUgCBN8vrz+zFjVyQ8FWkOlg4NQiZMB5QS8QO3mpOaKnL0Z2EKvNMSILEThKhCg zMKPVxYJh23qm9KNW7pArPynMqZDiErsTMqI+LRi3QAgkFUbXpuFKhSYZALd0O5RKa2z9EYKBbpb qxIKsjUPRgD7I2XYV6wyrOw92ykExP8NW4URhknC5dKGE4v4NENQj2jXjmfNgOZDaXb5glRmXQ33 YEWQYNcZFnrYcIQLNzyTFDQNkXIff0ExVlY4srziQk43inZgL4rwxxINMvpFFAz1KOODHiu+4aEw NEjFl5B3JIKWKF3k6I9bfUGp5ZZcdunll5IA4cuHvQQJ5gcsoCWOOUwgltIwAKRxJgbIkJAQZEq0 2YliZnpZZ4BH3CnYOXldOUOfQoYDqF1LFHbXCrO8xmRsfoXDXJ6ChjCAH3QlhJcT6VWE6FCkfCco CgrMFsROrIEX3o2whVjWDjoJccN3LdggSGXLCdLEgHr1lyU3O3QxhgohNKXJCWv8JQr/PDdaqd6w 2rj1inLiGeiCJoDspAoQlYE6QWLSECehcWIYxIQES6zhbn1iImTHEQyqJ4eIxJJoUBc+3CbBuwZE V5cJPPkIjFDdeEabQbd6WgICTxiiz0f5dBKquXF6k4senwEhYGnKEFJeGrxUZy8dB8gmAXI/sPvH ESfCwVt5hTgYiqQqtdRNHQIU1PJ33ZqmzgE90OwLaoJcnMop1WiMmgkPHQRIrwgFuNV90A3doNKT mrKIN07AnGcI9BQjhCBN4RfA1qIZnMqorJCogKfGQnxSCDilTVIA0yl5ciTovgLuBDKFUDE9aQcw 9SA+rjSNf9/M1gxrj6VwDTS0IUSElMzBfsj0NFXR2kwsV1A5IF1grLgLL/r1R40BZEnuBWgmQEyb jqRwSAt6bqMCOFkvKFN2GPPkUzIm/SCF8z8pVzpbjVnMsy0vOr1hw3SaSRUhpY09v0z0J1FnwzPl@@NL
Many thanks to all who helped this Informix newbie out; among whom are: Andrew Ford, Jack Parker, Madison Pruet, Anup Agrawal, Art Kagel (sorry if I missed anyone). This did the trick for me. I knew a modulus routine needed to be used, but had no idea how to implement. update <table> set <field> = <field> + 1 where abs (mod (<field>, 2)) = 1; ----- Original Message ----- I am trying to increment by 1 all odd numbers in a list, so that all the numbers end of being even. I can get my list by dividing by 2, but then how do I take the ??.5 entries and add 1 to each of them.