I need to negate the value of a column for all the rows in a column. I am trying to do so using the following query, but it is not updating any Row:
sqliteDatabase.rawQuery("UPDATE "+ SQL_TABLE_NAME + " SET "+ COL_1 +" = " + "-"+COL_1 , null);
Where COL-1 = col_1, which is of type integer in the table.
–Twinks
You could Multiply the column by -1
Mind you saying that, your query format works for me;
If I were you I’d create a string and set your query to that so you can check it’s being set as you expect:
Does your SQL_TABLE_NAME have a space in it? Try wrapping it in square brackets, and perhaps the same with your column name.
Edit:
I would recommend updating primary keys to be negative, but to accomplish this you could do something like this:
(but this will duplicate your table, you might want to shove the data into a temp table) – however I think this is a horrible solution. I’d try and find a way to restructure your table schema so it isn’t the primary key.