Solved

Manipulating SMALLMONEY data type

Posted on 2006-07-05
1
993 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
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to export SQL to firebase ? 7 67
Problem with email format from SQL DB 4 34
t-sql need help on t-sql 10 25
SQL Backup Question 2 29
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

809 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