November 28, 2013 at 7:19 am
Hi all the clever ones
I have a variable
someVariable(varchar(30), null) in our database
The vaues in this variable look like this:
8.000
7.000
6.000
How can I have these values displayed as a percentage?
8%
7%
6%
Kind regards
Fred
November 28, 2013 at 9:04 am
What would happen with a value like 8.352?
November 28, 2013 at 9:52 am
This link should explain what needs to be done.
http://www.sqlservercentral.com/Forums/Topic558696-338-1.aspx
However, you may need an additional cast since your numerics are stored in a non-numeric datatype.
Also, if you look at the solution, it is a lot of work to get what you want and depending upon how many rows this is being applied against, it could slow the query down. That is why it is recommended that formatting of this nature be done at the presentation layer instead of the backend.
__________________________________________________________________________________________________________
How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/
November 28, 2013 at 2:24 pm
Your client application should take care of formatting.
November 28, 2013 at 11:03 pm
Hi Luis
It's always rounded to the full decimal, ie, 7.000, 8.000.
Kind regards
November 28, 2013 at 11:04 pm
Hi Alex
Unfortunately it does not, hence my question.
Kind regards
November 29, 2013 at 2:20 am
Alexander Suprun (11/28/2013)
Your client application should take care of formatting.
Sometimes the client application is less suetable for the formatting.
For example I sometimes do the formatting within SQL-server when serving for the Reporting services. Although within the reporting there are plenty of possibilities to do 'presentation', you always need plenty of locations to get this in the code.
So although SSRS should do all presentation functions, I do often shift presentation code to a Stored procedure, for me this makes the code more flexible and cheaper to maintain.
Ben
November 29, 2013 at 6:57 am
CAST(CAST(someVariable as int) as varchar(30)) + '%'
Far away is close at hand in the images of elsewhere.
Anon.
November 29, 2013 at 12:31 pm
frdrckmitchell7 (11/28/2013)
Hi AlexUnfortunately it does not, hence my question.
Kind regards
Understood by why not fix the client side? What is preventing that?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply