3

I have one table containing many columns. Using field calculator, I want to create a new column containing (for each line) the sum of all columns values. Pretty dumb, but just cannot find the correct expression to do this sum...

5

Using the field calculator:

"column1" + "column2" + "column3"

Make sure the columns are integer or float values and don't contain NULL values.

UPDATE:

Sum up columns with NULL values:

"column1" +  (CASE WHEN  "column2" IS NOT NULL THEN "column2" ELSE 0 END) + "column3"
  • Thanks, that's what I've been trying but it doesn't work. I was wondering if it was me or some other sort of problem. Glad to know it's not me ! – Legzav Oct 8 '13 at 6:35
  • Can you please specify what do you mean by it doesn't work at all or it gives you incorrect results? – Farhat Abbas Oct 8 '13 at 6:46
  • It doesn't work at all. I get only NULL values. It also desn't show any preview result in the field calculator. – Legzav Oct 8 '13 at 6:54
  • @Legzav: Can you confirm that all the columns (input and output) are of Numeric Data type? – Devdatta Tengshe Oct 8 '13 at 7:26
  • Yes, all columns are REAL, 20 length, 5 precision. Many fields have NULL value. Don't know if this can have an impact !? should I replace all NULL by 0 ? – Legzav Oct 8 '13 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.