I have a table i.e.
create table tbl (id int, col1 varchar(50), col2 varchar(50),col3 varchar(50))insert into tbl values (1,'20','25','50')
insert into tbl values (2,'30','35','60')
insert into tbl values (3,'AB','AB','50')
I want to sum of three columns, for this I am using
select id, sum(convert(decimal,col1)+convert(decimal,col2)+convert(decimal,col3)) as total from tbl group by id, col1, col2, col3
Now I want to ignore varchar values and see result like
id total
1 95
2 125
3 50
Please help someone...
What I have tried:
select id, sum(convert(decimal,col1)+convert(decimal,col2)+convert(decimal,col3)) as total from tbl group by id, col1, col2, col3