I'm writing a SQL script. I'd like to display the value I have in a
column of type FLOAT so that it appears with the commas in the correct
place. It displays now as 10000000.0; I'd like it to display as
10,000,000. Thanks for any help."Rick Charnes" <rickxyz--nospam.zyxcharnes@.thehartford.com> wrote in message
news:MPG.1cffedcae86a60059898e0@.msnews.microsoft.com...
> I'm writing a SQL script. I'd like to display the value I have in a
> column of type FLOAT so that it appears with the commas in the correct
> place. It displays now as 10000000.0; I'd like it to display as
> 10,000,000. Thanks for any help.
Your front-end application should really be doing this type of work, not the
database itself.
Rick Sawtell
MCT, MCSD, MCDBA|||Formatting should be done client side, not in SQL.
"Rick Charnes" <rickxyz--nospam.zyxcharnes@.thehartford.com> wrote in message
news:MPG.1cffedcae86a60059898e0@.msnews.microsoft.com...
> I'm writing a SQL script. I'd like to display the value I have in a
> column of type FLOAT so that it appears with the commas in the correct
> place. It displays now as 10000000.0; I'd like it to display as
> 10,000,000. Thanks for any help.|||Do this in the reporting tool / client application, or cast the value to
money (not good) and then use function "convert" to cast it to varchar with
style 1.
Example:
use northwind
go
select
convert(varchar(25), cast(cast(orderid as float) as money), 1)
from
dbo.orders
AMB
"Rick Charnes" wrote:
> I'm writing a SQL script. I'd like to display the value I have in a
> column of type FLOAT so that it appears with the commas in the correct
> place. It displays now as 10000000.0; I'd like it to display as
> 10,000,000. Thanks for any help.
>
Showing posts with label float. Show all posts
Showing posts with label float. Show all posts
Wednesday, March 21, 2012
Tuesday, February 14, 2012
display FLOAT datatype with commas?
Is it possible to display a FLOAT datatype with all its commas every
three digits? I can't figure out how to use CAST or CONVERT to do this.
(I know this kind of thing is usually done on the client side, but
that's not possible right now.) Thanks much.here you go
DECLARE @.v float
SELECT @.v = 1322323.6666
SELECT CONVERT(VARCHAR,convert(money,@.v),1)
http://sqlservercode.blogspot.com/|||Why is this a float?
Anyway, see http://tinyurl.com/zlbmw
This is not pretty.
"Rick Charnes" <rickxyz--nospam.zyxcharnes@.thehartford.com> wrote in message
news:MPG.1e7917a698fb998c989921@.msnews.microsoft.com...
> Is it possible to display a FLOAT datatype with all its commas every
> three digits? I can't figure out how to use CAST or CONVERT to do this.
> (I know this kind of thing is usually done on the client side, but
> that's not possible right now.) Thanks much.|||FANTASTIC. Thank you.
Is there a way to right-justify the output? (I know we have character
data now, so it may not be possible?) Thanks.
In article <1141853921.455400.117020@.j52g2000cwj.googlegroups.com>,
denis.gobo@.gmail.com says...
> here you go
> DECLARE @.v float
> SELECT @.v = 1322323.6666
> SELECT CONVERT(VARCHAR,convert(money,@.v),1)
> http://sqlservercode.blogspot.com/
>|||What if it's a bigger FLOAT value than MONEY can support?
DECLARE @.v float
SELECT @.v = 1321324441322323.6666
Also, you should always specify the size of your VARCHAR parameters, IMHO.
"SQL" <denis.gobo@.gmail.com> wrote in message
news:1141853921.455400.117020@.j52g2000cwj.googlegroups.com...
> here you go
> DECLARE @.v float
> SELECT @.v = 1322323.6666
> SELECT CONVERT(VARCHAR,convert(money,@.v),1)
> http://sqlservercode.blogspot.com/
>|||> Is there a way to right-justify the output?
Umm, sure, you could say RIGHT(SPACE(30)+...stuff..., 30)
But what application is consuming this result that can't right-justify ?
Are you going to ask for a way to embed <img> tags next? :-)
T-SQL is not meant to be a presentation language.|||What is the basic principle of a tiered architecture? We do display
formatting in the front end and never in the database. Since FLOAT
can come back as exponential notation, you really don't want to do it
in SQL.|||Brilliant. Thank you VERY much. Much appreciated. I know T-SQL is not
meant to be a presentation language, but for a very quick one-time
temporary project I am forced to use it as such. This is perfect.
Thank you.
In article <OPUigrvQGHA.4956@.TK2MSFTNGP09.phx.gbl>,
ten.xoc@.dnartreb.noraa says...
> Umm, sure, you could say RIGHT(SPACE(30)+...stuff..., 30)
> But what application is consuming this result that can't right-justify ?
> Are you going to ask for a way to embed <img> tags next? :-)
> T-SQL is not meant to be a presentation language.
>
>
three digits? I can't figure out how to use CAST or CONVERT to do this.
(I know this kind of thing is usually done on the client side, but
that's not possible right now.) Thanks much.here you go
DECLARE @.v float
SELECT @.v = 1322323.6666
SELECT CONVERT(VARCHAR,convert(money,@.v),1)
http://sqlservercode.blogspot.com/|||Why is this a float?
Anyway, see http://tinyurl.com/zlbmw
This is not pretty.
"Rick Charnes" <rickxyz--nospam.zyxcharnes@.thehartford.com> wrote in message
news:MPG.1e7917a698fb998c989921@.msnews.microsoft.com...
> Is it possible to display a FLOAT datatype with all its commas every
> three digits? I can't figure out how to use CAST or CONVERT to do this.
> (I know this kind of thing is usually done on the client side, but
> that's not possible right now.) Thanks much.|||FANTASTIC. Thank you.
Is there a way to right-justify the output? (I know we have character
data now, so it may not be possible?) Thanks.
In article <1141853921.455400.117020@.j52g2000cwj.googlegroups.com>,
denis.gobo@.gmail.com says...
> here you go
> DECLARE @.v float
> SELECT @.v = 1322323.6666
> SELECT CONVERT(VARCHAR,convert(money,@.v),1)
> http://sqlservercode.blogspot.com/
>|||What if it's a bigger FLOAT value than MONEY can support?
DECLARE @.v float
SELECT @.v = 1321324441322323.6666
Also, you should always specify the size of your VARCHAR parameters, IMHO.
"SQL" <denis.gobo@.gmail.com> wrote in message
news:1141853921.455400.117020@.j52g2000cwj.googlegroups.com...
> here you go
> DECLARE @.v float
> SELECT @.v = 1322323.6666
> SELECT CONVERT(VARCHAR,convert(money,@.v),1)
> http://sqlservercode.blogspot.com/
>|||> Is there a way to right-justify the output?
Umm, sure, you could say RIGHT(SPACE(30)+...stuff..., 30)
But what application is consuming this result that can't right-justify ?
Are you going to ask for a way to embed <img> tags next? :-)
T-SQL is not meant to be a presentation language.|||What is the basic principle of a tiered architecture? We do display
formatting in the front end and never in the database. Since FLOAT
can come back as exponential notation, you really don't want to do it
in SQL.|||Brilliant. Thank you VERY much. Much appreciated. I know T-SQL is not
meant to be a presentation language, but for a very quick one-time
temporary project I am forced to use it as such. This is perfect.
Thank you.
In article <OPUigrvQGHA.4956@.TK2MSFTNGP09.phx.gbl>,
ten.xoc@.dnartreb.noraa says...
> Umm, sure, you could say RIGHT(SPACE(30)+...stuff..., 30)
> But what application is consuming this result that can't right-justify ?
> Are you going to ask for a way to embed <img> tags next? :-)
> T-SQL is not meant to be a presentation language.
>
>
Subscribe to:
Posts (Atom)