Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Better way to convert to percentage

Author  Topic 

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-03 : 13:13:44
I'm currently converting percentages, but doubt if it's the best way

Example: converting .69 to 69.0 via this logic

SELECT
.69 * 100

Perhaps using the CONVERT function?

I tried:
CONVERT(PERCENT,.69)
with no luck

Show me the light!

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-02-03 : 13:17:11
69 percent is 00.69 not 69.00. So I think you are talking about the presentation of the data. Most presentation software has lots of numeric and date formatting options. Can you do it there?

Be One with the Optimizer
TG
Go to Top of Page

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-06 : 09:59:44
Thanks TG, yes I'm just trying to make it pretty. Anyone know how to present .69 as %69?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-06 : 10:05:56
If you use Front End Application, why cant you do something like this?

value*100 & "%"

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-02-06 : 10:56:43
SQL Server is not for making things "pretty". Query Analyzer is NOT a reporting tool.
Use MS Access Data Projects, Crystal Reports, Active Reports, even Excel, and they will be able to display the data the way you like. And chances are they would rather recieve a percentage as 0.69 than as 69.0.
Go to Top of Page

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-06 : 11:35:07
No offense blindman, but if you don't want to provide help why post? This is the second time you've added no value.
Go to Top of Page

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-06 : 11:37:24
This works:
SELECT
CONVERT(VARCHAR(20),(.69 * 100)) + '%'
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-02-06 : 11:46:48
Good advice has value. Bad advice does not. I gave him good advice, and I stand by it. If you want to help him avoid "best practices", then maybe that should be your specialty. I promise not to encroach upon your area of expertise...
Go to Top of Page

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-06 : 11:52:33
OK
Go to Top of Page

jrauls
Starting Member

1 Post

Posted - 2010-11-30 : 13:43:09
FYI - When percentage set as Varchar, sorting ASC or DESC based on percentages sorts as text, not a number...

JD Rauls
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-30 : 14:06:06
wow. bumped a 4 yr old post to enlighten us with that?
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2010-12-02 : 13:40:00
Totally worth it to remind me, once again, just how witty and charming I can be when I try.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

moonshiner
Starting Member

1 Post

Posted - 2012-01-24 : 17:01:21
Best practice IMHO would be:
cast(convert(money,(0.69*100)) as varchar(max)) + '%'
this way he gets a consistent 2 decimal place for all responses.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-24 : 18:06:52
quote:
Originally posted by moonshiner

Best practice IMHO would be:
cast(convert(money,(0.69*100)) as varchar(max)) + '%'
this way he gets a consistent 2 decimal place for all responses.


Are you trolling?

If so, respect! that's pretty witty.

If you are serious........ no, no, no, no, no.

do it in the front end, why turn your expensive database server into a string.format whore?

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -