Solved

Manipulating SMALLMONEY data type

Posted on 2006-07-05
1
995 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 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Resume 5 46
What Is an Error? 2 30
SQL Query - Multiple match on field with no extras 7 17
SQL Query logic question 14 32
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

697 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