In sql server converting the value of records in a table with data type varchar to integer or decimal so you can get the sum of the value.
create table tm_Salary
(
ID int,
Salary_Amount varchar(50)
)
insert into tm_Salary values(1, '32.43');
insert into tm_Salary values(2, '43.33');
insert into tm_Salary values(3, '23.22');
sql Query:
SELECT
SUM(cast(Salary_Amount as decimal(4,2))) as Sum_Of_Salary
FROM tm_Salary
SUM(cast(Salary_Amount as decimal(4,2))) as Sum_Of_Salary
FROM tm_Salary
OR
SELECT
SUM(cast(isnull(Salary_Amount,0) as decimal(12,2))) as Sum_Of_Salary
FROM tm_Salary
SUM(cast(isnull(Salary_Amount,0) as decimal(12,2))) as Sum_Of_Salary
FROM tm_Salary
OR
SELECT
SUM(convert(decimal(10,2), Salary_Amount)) as Sum_Of_Salary
FROM tm_Salary
SUM(convert(decimal(10,2), Salary_Amount)) as Sum_Of_Salary
FROM tm_Salary
OR
No comments :
Post a Comment
Ask a Question?