Update build SQL to have a select case for each data type and add as cast to date on null

This commit is contained in:
Paul Trowbridge 2017-04-11 11:52:38 -04:00
parent 99a5318f4d
commit 51f35f9337

View File

@ -1877,19 +1877,32 @@ Public Function ADOp_BuildInsertSQL(ByRef tbl() As String, target As String, tri
rec = rec & "("
For j = 0 To UBound(tbl, 1)
If j <> 0 Then rec = rec & ","
If ftype(0)(j) <> "S" Then
If tbl(j, i) = "" Then
rec = rec & "NULL"
Else
rec = rec & Replace(tbl(j, i), "'", "''")
End If
Else
If trim Then
rec = rec & "'" & LTrim(RTrim(Replace(tbl(j, i), "'", "''"))) & "'"
Else
rec = rec & "'" & Replace(tbl(j, i), "'", "''") & "'"
End If
End If
Select Case ftype(0)(j)
Case "N" '-------N = numeric but should probably be N for numeric----
If tbl(j, i) = "" Then
rec = rec & "NULL"
Else
rec = rec & Replace(tbl(j, i), "'", "''")
End If
Case "S" '-------S = string------------------------------------------
If trim Then
rec = rec & "'" & LTrim(RTrim(Replace(tbl(j, i), "'", "''"))) & "'"
Else
rec = rec & "'" & Replace(tbl(j, i), "'", "''") & "'"
End If
Case "D" '-------D = date---------------------------------------------
If LTrim(RTrim(tbl(j, i))) = "" Then
rec = rec & "CAST(NULL AS DATE)"
Else
rec = rec & "'" & tbl(j, i) & "'"
End If
Case Else '-------Assume text------------------------------------------
If trim Then
rec = rec & "'" & LTrim(RTrim(Replace(tbl(j, i), "'", "''"))) & "'"
Else
rec = rec & "'" & Replace(tbl(j, i), "'", "''") & "'"
End If
End Select
Next j
rec = rec & ")"
sql = sql & rec
@ -1898,3 +1911,4 @@ Public Function ADOp_BuildInsertSQL(ByRef tbl() As String, target As String, tri
ADOp_BuildInsertSQL = sql
End Function