March 10, 2009 at 5:27 am
do we have a replacment for replacement of format(0,"percent") in SQL?
March 10, 2009 at 5:36 am
not built in , no; typically formatting is left for the presentation layer, like vb;
you can do something pretty close:
declare @val decimal (12,6)
set @val = 0.43365
select convert(varchar,convert(decimal(5,2),@val* 100.0)) + '%'
--43.37%
Lowell
March 10, 2009 at 7:16 am
Glad Lowell and I posted the same answer since the post was duplicated (http://www.sqlservercentral.com/Forums/Topic672270-338-1.aspx). Please don't post more than once.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
March 10, 2009 at 7:22 am
just realized that sorry...
But thank you both for your posts.
Many Thanks....
November 18, 2013 at 7:24 pm
Lowell (3/10/2009)
not built in , no; typically formatting is left for the presentation layer, like vb;you can do something pretty close:
declare @val decimal (12,6)
set @val = 0.43365
select convert(varchar,convert(decimal(5,2),@val* 100.0)) + '%'
--43.37%
Strangely enough, the Format() function has been added to SQL Server 2012.
http://technet.microsoft.com/en-us/library/hh213505.aspx
No idea why they would have added this, as Lowell said, better left to the presentation layer. Maybe if your presentation layer is a bit lacking, or for ad-hock querying it's useful.
November 18, 2013 at 11:08 pm
davoscollective (11/18/2013)
Lowell (3/10/2009)
not built in , no; typically formatting is left for the presentation layer, like vb;you can do something pretty close:
declare @val decimal (12,6)
set @val = 0.43365
select convert(varchar,convert(decimal(5,2),@val* 100.0)) + '%'
--43.37%
Strangely enough, the Format() function has been added to SQL Server 2012.
http://technet.microsoft.com/en-us/library/hh213505.aspx
No idea why they would have added this, as Lowell said, better left to the presentation layer. Maybe if your presentation layer is a bit lacking, or for ad-hock querying it's useful.
Sometimes... there is no "presentation layer". For example, I didn't write an app for my morning reports and I've never written an app to export data, which may be required in a certain format by the receiver of the data.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply