Chức năng: Chuẩn bị giá trị cho câu lệnh SQL
Ngôn ngữ: asp - Nhóm: database
CÚ PHÁP
currency = SQL_Currency(currencyvalue, databasetype)
Hàm SQL_Currency chuẩn bị giá trị số cho câu lệnh SQL
VÍ DỤ
<%
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 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
%>