SQL_Currency Function:
Prepare currency for SQL query.
Description:
The SQL_Currency Function prepares a currency value for SQL.
Syntax:
currency = SQL_Currency(currencyvalue, databasetype)
Example:
<%
Dim a a = SQL_Currency("20,15", "MSAccess") '--- MSAccess, MySQL, Oracle '--- returns 20,15 as currency
a = SQL_Currency("20,15", "MSSQL") '--- returns CONVERT(MONEY, '" & Replace("20,15", ",", ".") & "', 0)
%>
ASP Source Code:
<%
Public Function SQL_currency(ByRef acExpression, ByRef DbType) acExpression = Replace(acExpression, ",", ".") '--- If Empty Expression If acExpression = "" Then '--- Return Null SQL_currency = "NULL" '--- Else expression has content Else '--- Prepare for Errors On Error Resume Next '--- Attempt to convert expression to currency If LCase(DbType) = "mssql" Then SQL_currency = "CONVERT(MONEY, '" & Replace(acExpression, ",", ".") & "', 0)" '--- MSSQL Database '--- alternative method: CAST('" & request.form(Field) & "' AS MONEY) Else SQL_currency = acExpression End If '--- If error occured If Err Then '--- Clear Error Err.Clear SQL_currency = "NULL" End If '--- Err End If '--- acExpression = "" End Function '--- SQL_currency
%>
|