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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 display zero change to blank space
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

Hong Kong
165 Posts

Posted - 08/12/2014 :  23:48:43  Show Profile  Reply with Quote
I want edit this query how i can to do this ?

select item,sum(salesamt *saleqty) /sum(salesamt) as gp from saleheader
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

Aged Yak Warrior

United Kingdom
555 Posts

Posted - 08/13/2014 :  05:25:14  Show Profile  Reply with Quote
[PercentofGP] = convert(varchar, convert(decimal(5,2), 100.0 * (salesamt) * (saleqty) / (salesamt))) + '%'
from saleheader

[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!

Edited by - sz1 on 08/13/2014 05:46:55
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000