Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Manipulating SMALLMONEY data type

Posted on 2006-07-05
1
Medium Priority
?
1,012 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

636 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