How to calculate the sum of values in a column using SQL query, wherein the column name has comma in it? Below is a sample table:
Saint Petersburg, Russia
7.34
29.35
4.4
Output required== SUM(7.34+29.35+4.4) Thanks
How to calculate the sum of values in a column using SQL query, wherein the column name has comma in it? Below is a sample table:
Saint Petersburg, Russia
7.34
29.35
4.4
Output required== SUM(7.34+29.35+4.4) Thanks
Is this what you want?
select sum([Saint Petersburg, Russia])
from t;
You need to escape the column name and the traditional escape method in SQL Server uses square braces. Double quotes can also be used.
If the issue is that 'Saint Petersburg, Russia'
is a potential value in a character column you want to sum, then use try_convert()
:
select sum(try_convert(numeric(20, 4), col)
from t;