Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add % sign to result 1

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
972
GB
Hi

I have the following code

Select (sum(TotalSellPrice) - sum(TotalCostPrice)) / sum(TotalsellPrice)* 100 as Margin
from OrderHeader where DateTimeCreated >= DATEADD(day, datediff(day,0,getdate()),0) AND DateTimeCreated <= DATEADD(day, datediff(day,0,getdate()),0) + 1
AND OrderType = 1
AND Deleted = 0

I want to add the % sign to the result AS Margin.

I have tried CAST and + '%' in several places but cant seem to get it working.

Any ideas please

Thanks
 
Code:
Select Convert(Varchar(20), (sum(TotalSellPrice) - sum(TotalCostPrice)) / sum(TotalsellPrice) * 100) + ' %' as Margin

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
How about
Code:
Select Format((sum(TotalSellPrice) - sum(TotalCostPrice)) / sum(TotalsellPrice),'p2') as Margin
?

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Thanks for the replys

Select Convert(Varchar(20), (sum(TotalSellPrice) - sum(TotalCostPrice)) / sum(TotalsellPrice) * 100) + ' %' as Margin

This worked perfect
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top