Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 decimal as output problem

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2006-08-05 : 08:44:07
Hi

I have this stored procedure that show a sum of a shoppingcart.

[dbo].[p_ShoppingCartTotal]
(
@UserID nvarchar(50),
@TotalCost Decimal (9,2) OUTPUT
)
AS
SET NOCOUNT ON
SELECT
@TotalCost = CAST(SUM(tbl_Products.ProductPrice * tbl_ShoppingCart.Quantity) AS decimal(9,2))
FROM
tbl_ShoppingCart,
tbl_Products
WHERE
tbl_ShoppingCart.UserID = @UserID
AND
tbl_Products.NodeID = tbl_ShoppingCart.NodeID



I then use this line in my aspx page to display the output.

MyTotalCommand.Parameters.Add("@TotalCost", SqlDbType.Decimal, (9.2)).Direction = ParameterDirection.Output


But the problem is that even if the query should show for example 123,45 it never show any decimals.


What am I doing wrong here?

Best Regards

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-08-05 : 09:43:47
"But the problem is that even if the query should show for example 123,45 it never show any decimals."
did you try this in Query Analyser ?

you don't have to perform the CAST in your Stored Procedure. SQL Server will convert the result into data type of @TotalCost


KH

Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2006-08-05 : 09:53:06
Hi

I guess not, but the problem is the same anyway. No decimals :-(
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2006-08-05 : 09:58:36
:-) found the solution here..
http://support.microsoft.com/?kbid=892406

This part fixed the problem..

SqlParameter pOut = cmd.Parameters.Add("@pOut", SqlDbType.Decimal);
pOut.Precision = 19;
pOut.Scale = 4;
pOut.Direction = ParameterDirection.Output;


Thought it might help others with the same problem.


Cheers!
Go to Top of Page
   

- Advertisement -