views:

94

answers:

2

i want to show some data in percent. i have a mathematics formula like:

(qty(S) + qty(B))/qty(id)*100%

could i show the result for example like 25%? how do i do that?

+1  A: 

It's a presentation thing, but it's handled in the same fashion. You need to change the data type of the result to a string based one:

CAST((qty(S) + qty(B))/qty(id)*100 AS CHAR(2))+'%'
OMG Ponies
Thanks for the clarification. And nice answer.
JoshD
@JoshD: I didn't mean for you to delete your answer, just correct the syntax.
OMG Ponies
My answer was being misinformative (that's a word now), and fixing it would essentially mean copying your answer. I figured I'd clear away the confusion.
JoshD
A: 

Databases are used for storing data. Presentation of data should not be in its responsibilities. By that, I mean you should very rarely thing about storing a string value in the database like '75%'.

If you want specific formatting, the best place to do it is after extracting the data:

select concat(your_column,'%') as percent ...

Because concat expects strings, numeric values are automagically cast into string before joining them together.

paxdiablo