"ConvertCurrency" User Defined Function

Description:

This user defined function converts an amount of money in US Dollars into an equivalent amount of money in the specified culture's monetary system. This equivalent amount and form of money is represented by the Currency user defined type which is based on the Currency  managed class. This user defined function is based on the ConvertCurrency  managed method. Both the class and the method are stored the database server as the StoreServerComponents  assembly.

If the currency conversion cannot occur because there is insufficient data in the database to perform the currency conversion, then the specified amount is returned in the form of US Dollars.

Note: A highly simplified algorithm is used to convert from US dollars to a different currency. Realistic currency conversion algorithms are much more complex, and beyond the scope of this sample.

Definition:
CREATE FUNCTION DBO.ConvertCurrency
(
	@fromAmount AS money,
	@toCultureName AS nvarchar(10)
)
RETURNS Currency
AS EXTERNAL NAME [ConversionFunction]:[Microsoft.Samples.SqlServer.CurrencyConverter]::ConvertCurrency

Database Tables Used:

CurrencyRate:  The CurrencyRate table contains exchange rates between one currency and another. The exchange rates are for specific times and dates.