# Decimal result - Microsoft SQL / MS SQL Server

Hi, I have select statement which returns value without leading zero: SELECT cast(field1 as decimal(38,2)) FROM table1 The result is: ..23 I would like that result is: 0.23 Does anybody know the answer? Thank you, Simon...

1. ## Decimal result

Hi,

I have select statement which returns value without leading zero:

SELECT cast(field1 as decimal(38,2)) FROM table1

The result is:
..23

I would like that result is:

0.23

Thank you,
Simon

Simon Guest

2. ## Re: Decimal result

SELECT cast(cast(.234223 as decimal(38,2)) as varchar(10))

The question is WHY.
It is good practice to do this at the presentation layer.

"Simon" <si> wrote in message
news:3f310ed4\$s5.net...

raydan Guest

3. ## Re: Decimal result

Raydan,

Actually, the value in question was of scale 2 & so, .2344 will need a scale
of 4 for proper representation as DECIMAL. So, effectively, the 3rd
parameter for STR has to be changed to 4. If the scale needs to be set as 2
in the result, you are correct.

--
- Anith

Anith Guest

4. ## Re: Decimal result

I was just nit-picking. :-)

"Anith Sen" <com> wrote in message
news:e%phx.gbl...
scale

raydan Guest

5. ## Re: Decimal result

Can I join in? Depending on the type of the input, there can
be some surprises:

declare v float
set v = 0.235
SELECT STR(v, LEN(v), 2)
SELECT cast(cast(v as decimal(38,2)) as varchar(10))

-- Steve Kass
-- Drew University
-- Ref: B50C89B7-8B02-4948-BD4B-13C25856642A

raydan wrote:

>scale
>

>2
>

>
>
>
>[/ref]

Steve Guest

6. ## Re: Decimal result

here you go about datatypes a g a i n....

--
-oj

"Steve Kass" <edu> wrote in message
news:phx.gbl...
> >scale
> >
> > [/ref][/ref]
as
> >2
> >
> >
> >
> >
> >
> >[/ref]
>[/ref]

oj Guest

7. ## Re: Decimal result

Just be glad I've been quiet about RAND(X) for a while... ;)

SK

oj wrote:
[/ref]
>as
>
> [/ref]
>
>
>
>[/ref]

Steve Guest

8. ## Re: Decimal result

hehehehe....for a while...

shouldn't you be answering the "Convert / Decimal / Float" post... <G>

--
-oj

"Steve Kass" <edu> wrote in message
news:e\$phx.gbl...
> >as
> >
> >
> >
> >
> >
> >[/ref]
>[/ref]

oj Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•