Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread CAST as Money
Wed, May 6 2009 3:12 PMPermanent Link

"Halim"
Hello all, =20
I'm trying to apply CAST function within my query so we can get clean =
and easy to read dataset.
This is a simple example:
SELECT  'Purchased '+ CAST(CAST((balance) AS MONEY)  AS CHAR(10))  FROM =
Card =20

I want my query to give me: "Purchased 5.00" but  it gave me "Purchased =
5" instead.
I also tried SELECT  'Purchased '+ CAST(CAST((balance) AS DECIMAL(0,2))  =
AS CHAR(10))  FROM Card but we keep geting the same result.
We are using DBISAM 4.26 build 3.
Any help will be greatly appreciated.
Thank you,
-Halim

Fri, May 8 2009 5:19 AMPermanent Link

"John Hay"
Halim

>I'm trying to apply CAST function within my query so we can get clean and
easy to read dataset.
>This is a simple example:
>SELECT  'Purchased '+ CAST(CAST((balance) AS MONEY)  AS CHAR(10))  FROM
Card

>I want my query to give me: "Purchased 5.00" but  it gave me "Purchased 5"
instead.

Presuming balance is a currency/float type with no more than 2 decimal
places then

SELECT 'Purchased '+SUBSTRING(CAST(balance+0.001 AS CHAR(10)) FROM 1 for
LENGTH(CAST(balance+0.001 AS CHAR(10)))-1) FROM Card

John

Fri, May 8 2009 9:00 AMPermanent Link

"Halim"
That's what I needed.
Thank you John,
-Halim
"John Hay" <j.haywithoutdot@crbsolutionsremoveallthis.co.uk> wrote in
message news:A81CEE96-41F5-4B26-91F1-2E4EC591B6CA@news.elevatesoft.com...
> Halim
>
>>I'm trying to apply CAST function within my query so we can get clean and
> easy to read dataset.
>>This is a simple example:
>>SELECT  'Purchased '+ CAST(CAST((balance) AS MONEY)  AS CHAR(10))  FROM
> Card
>
>>I want my query to give me: "Purchased 5.00" but  it gave me "Purchased 5"
> instead.
>
> Presuming balance is a currency/float type with no more than 2 decimal
> places then
>
> SELECT 'Purchased '+SUBSTRING(CAST(balance+0.001 AS CHAR(10)) FROM 1 for
> LENGTH(CAST(balance+0.001 AS CHAR(10)))-1) FROM Card
>
> John
>
>
Image