Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4098866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:21:31+00:00 2026-05-20T20:21:31+00:00

I need to negate the value of a column for all the rows in

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:21:32+00:00Added an answer on May 20, 2026 at 8:21 pm

    You could Multiply the column by -1

     Update SQL_TABLE_NAME Set COL_1 = COL_1 * -1
    

    Mind you saying that, your query format works for me;

     Update tPerson Set Age = -Age
    

    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:

     String sql = "UPDATE "+ SQL_TABLE_NAME + " SET "+ COL_1 +" = " + "-" + COL_1;
     sqliteDatabase.rawQuery(sql, null); //breakpoint here, and check sql var
    

    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:

     SET IDENTITY_INSERT Person ON
    
     Insert Into Person ([Id], [Name], [Age])
     Select -[Id], [Name], [Age] From Person
    
     SET IDENTITY_INSERT Person OFF
    

    (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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find in project files all occurrences of <LIB> or <M> but
I need to negate multiple conditions at once using Propel. E. g. a corresponding
Need help with a query that I wrote: I have three tables Company id
I need to negate very large number of doubles quickly. If bit_generator generates 0,
I am having a filter for the following regular expressions [^@()[]\;:,<>]+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ I need to
I need to perform case-insensitive queries on username by default when using the Django
I've searched for questions like this, but all the cases I found were solved
I am working on an app, and need to keep track of how any
I'm trying to use regular expressions to match a string that does not contain
Need to launch a new ASP.NET site on this server but need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.