SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

usafelix
Yak Posting Veteran

Hong Kong
97 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
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
Constraint Violating Yak Guru

United Kingdom
443 Posts

Posted - 08/13/2014 :  05:25:14  Show Profile  Reply with Quote
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!

Edited by - sz1 on 08/13/2014 05:46:55
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.14 seconds. Powered By: Snitz Forums 2000