Showing posts with label cast. Show all posts
Showing posts with label cast. Show all posts

Friday, March 9, 2012

Decimals

How do I get sql server to display the decimals? None of
these work for example:
select convert(decimal(10,2), 190/90 ) as numberw
select cast((190/90) as float) as numberwHi,
Make one of the numbers a float by adding a dot after it like:
select 190/90.
HTH
Karl Gram
http://www.gramonline.com
"GoTo" <anonymous@.discussions.microsoft.com> wrote in message
news:e13701c40b6d$51d59870$a401280a@.phx.gbl...
> How do I get sql server to display the decimals? None of
> these work for example:
> select convert(decimal(10,2), 190/90 ) as numberw
> select cast((190/90) as float) as numberw|||Convert the numbers first, then do the division:
select convert(decimal(10,2), 190)/90 as numberw
Jacco Schalkwijk
SQL Server MVP
"GoTo" <anonymous@.discussions.microsoft.com> wrote in message
news:e13701c40b6d$51d59870$a401280a@.phx.gbl...
> How do I get sql server to display the decimals? None of
> these work for example:
> select convert(decimal(10,2), 190/90 ) as numberw
> select cast((190/90) as float) as numberw

Wednesday, March 7, 2012

Decimal Help

I am having trouble with the following view in SQL:
SELECT CAST(AVG(L) AS Decimal(9, 1)) AS LAvg
FROM dbo.HOSurvey_holding
WHERE (L <> 0)
I want one decimal holder but when i have a whole number it doesnt put
a .0 after it? is this possible if so how would i do it? The data i
have in the database averages out to 4 and i would like for it to be
4.0
Any ideas on how i can fix the view so it adds the .0 after whole
numbers.That's a presentation layer issue basically. If you return numbers to your
application, your application should be able to present them in the
appropriate format to the user. VB, Excel, ASP etc all have the appropriate
controls for formatting.
But if you really need to do it in SQL Server, for example because you
create an export to a text file, you can use the STR function:
SELECT STR(AVG(L),10,1)AS LAvg
FROM dbo.HOSurvey_holding
WHERE (L <> 0)
Jacco Schalkwijk
SQL Server MVP
<pkruti@.hotmail.com> wrote in message
news:1113488579.279634.184360@.o13g2000cwo.googlegroups.com...
>I am having trouble with the following view in SQL:
> SELECT CAST(AVG(L) AS Decimal(9, 1)) AS LAvg
> FROM dbo.HOSurvey_holding
> WHERE (L <> 0)
> I want one decimal holder but when i have a whole number it doesnt put
> a .0 after it? is this possible if so how would i do it? The data i
> have in the database averages out to 4 and i would like for it to be
> 4.0
> Any ideas on how i can fix the view so it adds the .0 after whole
> numbers.
>

decimal data type serialized to binary

Hi,
I have the value 1234.1234 in a decimal field, converted to binary
(cast(myField as binary(13)), it gives 0x000000000013060001883a8f49. When I
use SqlDecimal in .NET, for the same value, I get 0x883a8f49 which makes
0x1306 the precision and scale (precision 19, so 0x13 and scale 6, so 0x06),
but what is the 0x0001? moreover, when I export to a file using bcp native
file type, the 0x0001 becomes 0x01 (loses a byte)
Can someone shed a light on this please?
Thanks
ThunderMusic
I think I found it. It would be to indicate a positive number. I still don't
understand why the cast operation gives 0001 and bcp gives 01, but still, it
seems to match anyway... Can someone confirm?
Thanks
ThunderMusic
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@.NoSpAm.com> wrote in message
news:%23Ebg7yEgHHA.4260@.TK2MSFTNGP03.phx.gbl...
> Hi,
> I have the value 1234.1234 in a decimal field, converted to binary
> (cast(myField as binary(13)), it gives 0x000000000013060001883a8f49. When
> I use SqlDecimal in .NET, for the same value, I get 0x883a8f49 which makes
> 0x1306 the precision and scale (precision 19, so 0x13 and scale 6, so
> 0x06), but what is the 0x0001? moreover, when I export to a file using bcp
> native file type, the 0x0001 becomes 0x01 (loses a byte)
> Can someone shed a light on this please?
> Thanks
> ThunderMusic
>