question

rajumaharjan avatar image
rajumaharjan asked

How to get sub total based on column that have decimals numbers in varchar ?

Example

1sum of 1.1 & 1.21.11.2sum of 1.2.1 & 1.2.21.2.11.2.210sum of 10.1 & 10.210.1sum of 10.1.1 & 10.1.210.1.110.1.210.2
sql query
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

You might need to edit this question. The formatting has made it confusing to read and I can't tell exactly what you are trying to acheive

0 Likes 0 ·

1 Answer

·
ckuroda1 avatar image
ckuroda1 answered

You may use the Cast operator to cast the decimal value to a string:

use AdventureWorks2012;

go

select sum([Weight]) as totalweight, cast(sum([Weight]) as varchar(20)) as StringTotalWeight from production.product where [Weight] is not null and color ='red'

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.