CAST to convert Expression to Money?

CAST to convert Expression to Money?

Post by Rick Curti » Fri, 31 Mar 2000 04:00:00



I am getting an error while trying to insert data into a table from an
ASP Page. I presume that it is because I am using an expression to
calculate a new price and inserting that price into the table without
defining the datatype.

Alter PROCEDURE sp_AvailableProductsView
AS
SELECT Category.CategoryName AS Category,
   Products.UnitPrice, Products.MSRP,
   ((Products.UnitPrice * Products.Discount) + Products.UnitPrice) AS
Price,
   (Products.MSRP - ((Products.UnitPrice * Products.Discount) +
Products.UnitPrice)) AS Savings,

The stored procedure runs fine by itself. Is there a way to encapsulate
the expression in a CAST to convert to money. I've tried

  CAST(((Products.UnitPrice * Products.Discount + Products.UnitPrice) AS
Price) AS Money)

But it doesn't work.

--
Rick Curtis
Director, Outdoor Action Program
Princeton University
609-258-3552
http://www.princeton.edu/~oa/

 
 
 

CAST to convert Expression to Money?

Post by joj.. » Fri, 31 Mar 2000 04:00:00


Hi Rick,
I don't have any experience with ASP so I can't speak to that issue,
however, I can tell you what is wrong with your CAST attempt -- you put
the alias for your field inside the CAST() ...  You would probably
receive the following error:
Server: Msg 156, Level 15, State 1, Line xxx
Incorrect syntax near the keyword 'as'.

Try this instead:
CAST((Products.UnitPrice * Products.Discount + Products.UnitPrice) AS
Money) As Price

"Price" is the name for the final result, after all calculations and
datatype conversions have been done.

Hope this helped a little!



> I am getting an error while trying to insert data into a table from an
> ASP Page. I presume that it is because I am using an expression to
> calculate a new price and inserting that price into the table without
> defining the datatype.

> Alter PROCEDURE sp_AvailableProductsView
> AS
> SELECT Category.CategoryName AS Category,
> Products.UnitPrice, Products.MSRP,
> ((Products.UnitPrice * Products.Discount) + Products.UnitPrice) AS
> Price,
> (Products.MSRP - ((Products.UnitPrice * Products.Discount) +
> Products.UnitPrice)) AS Savings,

> The stored procedure runs fine by itself. Is there a way to
encapsulate
> the expression in a CAST to convert to money. I've tried

> CAST(((Products.UnitPrice * Products.Discount + Products.UnitPrice) AS
> Price) AS Money)

> But it doesn't work.

> --
> Rick Curtis
> Director, Outdoor Action Program
> Princeton University
> 609-258-3552
> http://www.princeton.edu/~oa/

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

1. Cast/Convert, datetimes and money

(SQL7)
I can't find how to convert a float col to money and a datetime col to just
date (mm/dd/yy).
I have tried:

    select ...     cast(listprice as money), cast(invdate as datetime)

"as date" is invalid and the listprice displays as:

            20.0000               1999-09-23 00:00:00.000

I was expecting $20.00

2. Recordset.Filter property And Wildcards (?)

3. CAST expression error

4. Windows AND Macintosh Image Conversion/Display Library

5. CAST Expression error

6. backup database and restore to another server

7. CAST expression error

8. cast varchar into money

9. Cast small money as decimal error

10. [PATCH] Contrib C source for casting MONEY to INT[248] and FLOAT[48]

11. Contrib C source for casting MONEY to INT[248] and FLOAT[48]