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?
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?
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))+'%'
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.