Home > database >  SQL Adding a minus in a number if it is in another
SQL Adding a minus in a number if it is in another

Time:10-29

I have a question for you, I don't know how to do it, I need to create a procedure if or case when. Relying on the back in the Salary column, some value has a minus, e.g. -316183.1021. This will add a minus to the value in the NOMINAL MAX column For example here: ( This is result after sql in excel )

If SALARY = "-" then NOMINAL_MAX*(-1)```

enter image description here

CodePudding user response:

You can use the SIGN function:

SELECT NOMINAL_MAX * SIGN(SALARY) AS NOMINAL_MAX_New
FROM ...

CodePudding user response:

Try

  update <table>
  set nominal_max = -nominal_max
  where nominal_max > 0 and salary < 0
  • Related