 |
|
 |
|
Next: Problem with nested Select Statement
|
| Author |
Message |
External

Since: Jul 25, 2007 Posts: 12
|
(Msg. 1) Posted: Thu Jan 25, 2007 11:52 am
Post subject: format number with thousand-separator Archived from groups: microsoft>public>sqlserver>programming (more info?)
|
|
|
is there a built in function in sql server 2005 that will format a number
with commas as the thousand-separator?
ie., here's what i want to do:
input=1000
output=1,000
or
input=1000000
output=1,000,000
if there isn't a built-in function, can someone point me to a
user-defined-function that might do the trick?
thanks so much,
jt >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Mar 07, 2007 Posts: 15
|
(Msg. 2) Posted: Thu Jan 25, 2007 1:06 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
First of all, Aaron's answer was perfect given the amount of
description of the issue in the original posting. Since Aaron's reply
has now elucidated from you that your issue is in Microsoft Reporting
Services (the presentation layer in your system), there is no better
demonstration that his reply was perfect at pushing YOU to think
through your system and accurately identify where the problem is.
Now that we understand where the issue is, I found the following in BOL
in seconds:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/rptsrvr9/html/7852b4c7-3b45-406d-8e43-69c8cf2b710e.htm
Formatting Numeric and Date Values in a Report
You can specify a format for numeric and date values by updating the
Format property of its text box with a formatting string. For example,
you can set a text box for a numeric field to display the number as
currency. Reporting Services uses Microsoft .NET Framework formatting
strings or you can create a custom formatting string for the Format
property.
....
You can modify many of the format strings to include a precision
specifier that defines the number of digits to the right of the decimal
point. For example, a formatting string of D0 formats the number so
that it has no digits after the decimal point. You can also use custom
formatting strings, for example, #,###.
Have you tried defining a custom formatting string as per the manual?
On Jan 25, 3:23 pm, "JTL" wrote:
> BECAUSE IM PULLING DATA FOR MS REPORTING SERVICES AND THE ONLY FORMAT
> OPTIONS AVAILABLE ARE:
>
> 1234
> 1,234.00 (this one is close, but not what i want- this particular number
> will never have decimals so i don't want to waste space showing ".00")
> 1234.00
> 1.234123e+003
>
> its not helpful to reply when you don't have an answer, b/c then other
> people assume, by seeing a response next to the posting, that the problem
> has been solved.
>
> "Aaron Bertrand [SQL Server MVP]" wrote in messagenews:unj7UsLQHHA.4172@TK2MSFTNGP03.phx.gbl...
>
>
>
> > VB has format()
> > VBScript has formatnumber()
> > C# has string.format()
>
> > Why do you need to perform this presentation layer task in the database?
>
> > "JTL" wrote in message
> >
> >> is there a built in function in sql server 2005 that will format a number
> >> with commas as the thousand-separator?
>
> >> ie., here's what i want to do:
> >> input=1000
> >> output=1,000
>
> >> or
> >> input=1000000
> >> output=1,000,000
>
> >> if there isn't a built-in function, can someone point me to a
> >> user-defined-function that might do the trick?
>
> >> thanks so much,
>
> >> jt- Hide quoted text -- Show quoted text - >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
|
Aaron Bertrand [SQL Serve
|
External

Since: Jan 10, 2008 Posts: 2166
|
(Msg. 3) Posted: Thu Jan 25, 2007 3:00 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
VB has format()
VBScript has formatnumber()
C# has string.format()
Why do you need to perform this presentation layer task in the database?
"JTL" wrote in message
> is there a built in function in sql server 2005 that will format a number
> with commas as the thousand-separator?
>
> ie., here's what i want to do:
> input=1000
> output=1,000
>
> or
> input=1000000
> output=1,000,000
>
> if there isn't a built-in function, can someone point me to a
> user-defined-function that might do the trick?
>
> thanks so much,
>
> jt
>
>
>
> >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2006 Posts: 15
|
(Msg. 4) Posted: Thu Jan 25, 2007 3:00 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jul 25, 2007 Posts: 12
|
(Msg. 5) Posted: Thu Jan 25, 2007 3:00 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
BECAUSE IM PULLING DATA FOR MS REPORTING SERVICES AND THE ONLY FORMAT
OPTIONS AVAILABLE ARE:
1234
1,234.00 (this one is close, but not what i want- this particular number
will never have decimals so i don't want to waste space showing ".00")
1234.00
1.234123e+003
its not helpful to reply when you don't have an answer, b/c then other
people assume, by seeing a response next to the posting, that the problem
has been solved.
"Aaron Bertrand [SQL Server MVP]" wrote in message
> VB has format()
> VBScript has formatnumber()
> C# has string.format()
>
> Why do you need to perform this presentation layer task in the database?
>
>
>
>
>
> "JTL" wrote in message
>
>> is there a built in function in sql server 2005 that will format a number
>> with commas as the thousand-separator?
>>
>> ie., here's what i want to do:
>> input=1000
>> output=1,000
>>
>> or
>> input=1000000
>> output=1,000,000
>>
>> if there isn't a built-in function, can someone point me to a
>> user-defined-function that might do the trick?
>>
>> thanks so much,
>>
>> jt
>>
>>
>>
>>
>
> >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Jul 01, 2006 Posts: 15
|
(Msg. 6) Posted: Thu Jan 25, 2007 3:00 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
JTL wrote:
> BECAUSE IM PULLING DATA FOR MS REPORTING SERVICES AND THE ONLY FORMAT
> OPTIONS AVAILABLE ARE:
>
> 1234
> 1,234.00 (this one is close, but not what i want- this particular
> number will never have decimals so i don't want to waste space
> showing ".00") 1234.00 1.234123e+003
I'm sure this must be possible in Reporting services! I'm gonna look
at it later tonight, gotta go now.
> its not helpful to reply when you don't have an answer, b/c then
> other people assume, by seeing a response next to the posting, that
> the problem has been solved.
And it's also not polite to start shouting at someone who is trying to
help.
--
HTH,
Stijn Verrept. >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Nov 21, 2006 Posts: 285
|
(Msg. 7) Posted: Thu Jan 25, 2007 3:00 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
JTL wrote:
> BECAUSE IM PULLING DATA FOR MS REPORTING SERVICES AND THE ONLY FORMAT
> OPTIONS AVAILABLE ARE:
>
> 1234
> 1,234.00 (this one is close, but not what i want- this particular number
> will never have decimals so i don't want to waste space showing ".00")
> 1234.00
> 1.234123e+003
>
> its not helpful to reply when you don't have an answer, b/c then other
> people assume, by seeing a response next to the posting, that the problem
> has been solved.
>
It's not helpful to post questions and then argue about the answers
before you've researched the tools that you're using:
http://msdn2.microsoft.com/en-US/library/ms157406.aspx
See the part about custom format strings...
--
Tracy McKibben
MCDBA
http://www.realsqlguy.com >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Apr 11, 2007 Posts: 60
|
(Msg. 8) Posted: Thu Jan 25, 2007 3:00 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
its not helpful to reply when you don't have an answer, b/c then other
people assume, by seeing a response next to the posting, that the problem
has been solved.
You're absolutely right. And every time I see that Aaron has posted a
response, I open it to learn something new.
Vern Rabe
"JTL" wrote:
> BECAUSE IM PULLING DATA FOR MS REPORTING SERVICES AND THE ONLY FORMAT
> OPTIONS AVAILABLE ARE:
>
> 1234
> 1,234.00 (this one is close, but not what i want- this particular number
> will never have decimals so i don't want to waste space showing ".00")
> 1234.00
> 1.234123e+003
>
> its not helpful to reply when you don't have an answer, b/c then other
> people assume, by seeing a response next to the posting, that the problem
> has been solved.
>
>
>
> "Aaron Bertrand [SQL Server MVP]" wrote in message
>
> > VB has format()
> > VBScript has formatnumber()
> > C# has string.format()
> >
> > Why do you need to perform this presentation layer task in the database?
> >
> >
> >
> >
> >
> > "JTL" wrote in message
> >
> >> is there a built in function in sql server 2005 that will format a number
> >> with commas as the thousand-separator?
> >>
> >> ie., here's what i want to do:
> >> input=1000
> >> output=1,000
> >>
> >> or
> >> input=1000000
> >> output=1,000,000
> >>
> >> if there isn't a built-in function, can someone point me to a
> >> user-defined-function that might do the trick?
> >>
> >> thanks so much,
> >>
> >> jt
> >>
> >>
> >>
> >>
> >
> >
>
>
> >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Jul 25, 2007 Posts: 12
|
(Msg. 9) Posted: Thu Jan 25, 2007 3:43 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
ok ok- i'm sorry to have started the argument-thank you all for helping
solve my problem.
aaron, im also sorry about yelling in my response- that was rude, but i was
frustrated at the moment, and it has been my experience that when a response
is posted that does not answer the question at hand, the likelihood of
getting a valid answer dramatically decreases. obviously, this was not the
case in this posting.
at any rate, by applying the formatting string "N0", i was able to get the
exact format i needed. i had researched the issue prior to posting, but
had not been thorough enough. the example in BOL describes that "a
formatting string of D0 formats the number so that it has no digits after
the decimal point." In my hastiness, I didn't realize that this same logic
could be applied to the "N" formatting string, as well.
"Stijn Verrept" wrote in message
> Aaron Bertrand [SQL Server MVP] wrote:
>
>> VB has format()
>> VBScript has formatnumber()
>> C# has string.format()
>
> And Delphi has FloatToStrF
>
> And I agree with you
>
>
> --
> Kind regards,
>
> Stijn Verrept. >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
|
Aaron Bertrand [SQL Serve
|
External

Since: Jan 10, 2008 Posts: 2166
|
(Msg. 10) Posted: Thu Jan 25, 2007 4:01 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
> its not helpful to reply when you don't have an answer,
Well, maybe you can't see that my question was meant to derive more
information to help you better.
> b/c then other people assume, by seeing a response next to the posting,
> that the problem has been solved.
Maybe you assume that, but I don't know anyone who does.
And since you'd rather yell at me than do your own research, good luck with
your problem! >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Jan 25, 2007 Posts: 1
|
(Msg. 11) Posted: Thu Jan 25, 2007 9:02 pm
Post subject: Re: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
JTL wrote:
>is there a built in function in sql server 2005 that will format a number
>with commas as the thousand-separator?
>
declare @test as money
set @test = 19250500
select @test, left(convert(varchar(20), @test, 1), len(convert(varchar(20),
@test, 1)) -3)
or
declare @test as decimal
set @test = 19250500
select @test, left(cast(convert(varchar(20),cast(@test as money),1) as
varchar), len(convert(varchar(20),cast(@test as money),1)) -3) >> Stay informed about: format number with thousand-separator |
|
| Back to top |
|
 |  |
External

Since: Mar 11, 2009 Posts: 2
|
(Msg. 12) Posted: Wed Mar 11, 2009 3:25 am
Post subject: RE: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Mar 11, 2009 Posts: 2
|
(Msg. 13) Posted: Wed Mar 11, 2009 10:25 pm
Post subject: RE: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Nov 10, 2009 Posts: 1
|
(Msg. 14) Posted: Tue Nov 10, 2009 11:25 am
Post subject: RE: format number with thousand-separator [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
| Related Topics: | question about number format - I want to format the following numbers 189800 to $190K 2501000 to $2,501K I used the following query (not sure what other way I can do) but the problem is I don't know how to add comma. is there an easier way to format the numbers in query? SELEC...
isqlw results number format -
Regional settings - decimal separator - Hi! I would like to know which decimal separator is used on a computer, from a stored procedure. My stored procedure will insert a decimal value into a string, that must be formatted in a special way, and insert the string in a table. The problem is..
DateTime Format - Hello All, Is it possible to store the date as ' 02 - Apr - 2006 ' in the SQL datetime field? If it is please tell how to do. Thanks, karthick
Date Format - Hi All, Can any one tell me how to format the date time in tsql in this format mm/dd/yyyy hh:mm am/pm (1/22/2009 6:00am) Thanks Balaji -- Message posted via SQLMonster.com http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200804/1 |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|