Tax Component 

Posted by Philip Leitch Sunday, June 07, 2009 6:59:48 AM
 
IF EXISTS (SELECT 'x' FROM   sysobjects WHERE  name = 'TAX_Component')
 DROP FUNCTION TAX_Component
GO
Create FUNCTION dbo.TAX_Component
 (@Charge as Money,
  @TAX_Rate as numeric(12,4))
RETURNS  Money
AS
BEGIN
/*
Author: Philip Leitch
Date: 2001
Purpose: Determines the tax component of an already taxed value.
Copyright: Philip Leitch 2001
Licensing: This code may be used or modified but if the code is included in a software package attribution to me must be made.
Liability: The developer assumes all liability when using this code.
Notes:
This function was created for Goods and Services (GST) tax, a type of Value Added Tax (VAT).  The Tax portion
of a value is frequently required When only the total net (inclusive of tax) value is provided.  This function
will provide the tax component, given any charge and tax rate.
*/
  RETURN case when @TAX_Rate = 0 then 0 else cast(@Charge * 1/((1/@TAX_Rate)+1) as numeric(12,2)) end
END
GO
-- =============================================
-- Example to execute function
-- =============================================
declare @Amount as money
declare @TAX_Rate as float
set @amount = $100
set @TAX_Rate = 0.10 --Equates to TAX
select @Amount as Amount, @TAX_Rate as rate, dbo.TAX_Component(@Amount, @TAX_Rate) as TAX_Component, @Amount - dbo.TAX_Component(@Amount, @TAX_Rate) as Total_Exclusive_Charge
select 9.0900+ 90.9100


Copyright 2009 Philip Leitch