Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 display zero change to blank space

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2014-08-12 : 23:48:43
I want edit this query how i can to do this ?

select item,sum(salesamt *saleqty) /sum(salesamt) as gp from saleheader
output
item amt GP %
apple 5.00 123.000000
orange 20.00 83.000000000

Want to change
item amt GP %
apple 5.00 %123
orange 20.00 %80
Total 25
Average GP %13




sz1
Aged Yak Warrior

555 Posts

Posted - 2014-08-13 : 05:25:14
select
[item],
[amt],
[PercentofGP] = convert(varchar, convert(decimal(5,2), 100.0 * (salesamt) * (saleqty) / (salesamt))) + '%'
from saleheader


select
[Total] = sum([item]),
[AvgPercentofGP] = avg(convert(varchar,convert(decimal(5,2), 100.0 * (salesamt) * (saleqty) / (salesamt)))) + '%'
from saleheader


We are the creators of our own reality!
Go to Top of Page
   

- Advertisement -