Home > database >  SQL SUM with condition / Invalid column name 'SUM'
SQL SUM with condition / Invalid column name 'SUM'

Time:01-27

I'm trying to make a sum of the variable value/valeur with some conditions but I obtain this error: Invalid column name 'SUM'.

SELECT SUM[value/valeur] 
FROM [dbo].[tmp_norm_can]
WHERE [state/etat] = '1000' 
  AND [geo/geo] = '1' 
  AND [country/pays] != '999'

I attached an image of the database

Thank you very much!

enter image description here

CodePudding user response:

sum is a function. Try

SELECT SUM([value/valeur])
FROM [dbo].[tmp_norm_can]
WHERE [state/etat] = '1000' 
  AND [geo/geo] = '1'
  AND [country/pays] != '999'

CodePudding user response:

Try aliasing your column with a name different than "SUM".

  •  Tags:  
  • Related