?
Solved

Manipulating SMALLMONEY data type

Posted on 2006-07-05
1
Medium Priority
?
1,007 Views
Last Modified: 2013-12-03
Hi,

I'm using the SMALLMONEY data type.  I have a function that uses a string value passed from VB.NET to add the string to the SMALLMONEY value and return the result as SMALLLMONEY.  The following function works:

CREATE FUNCTION dbo.AddMoney
      (
      @ORIGINALVALUE AS SMALLMONEY, --The original Value to be added to
      @ADDAMOUNT AS VARCHAR(10) --The value to be added
      )
RETURNS SMALLMONEY
AS
      BEGIN
      DECLARE @RETURNAMOUNT AS SMALLMONEY
      SET @RETURNAMOUNT = CAST(@ADDAMOUNT AS SMALLMONEY)
      SET @RETURNAMOUNT = @RETURNAMOUNT + @ORIGINALVALUE
      RETURN @RETURNAMOUNT
      END

My question is:  I need to calculate a percentage of a SMALLMONEY value and return the result as a SMALLLMONEY.  So I need to pass in the Price to amend, and the percentage to calculate ie (17.5% TAX).  What would be the best types to pass in to the function and how would I manage the conversions to get an accurate result?
0
Comment
Question by:AMLabels
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1600 total points
ID: 17043943
NOTE:
  you should NOT use money and smallmoney as database field values, as this is a mix of value + currency.
  use decimal instead, and for DISPLAY (and possibly import), you can use the money data types.

Here a function (with money, but as noted above, you should not use money)

CREATE FUNCTION dbo.ComputeTax
     (
     @ORIGINALVALUE AS SMALLMONEY, --The original Value to be added to
     @TaxValue AS Decimal(10,4) --The tax value
     )
RETURNS SMALLMONEY
AS
     BEGIN
     DECLARE @RETURNAMOUNT AS SMALLMONEY
     SET @RETURNAMOUNT = @ORIGINALVALUE * @TaxValue / 100
     RETURN @RETURNAMOUNT
     END
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question