Results 1 to 6 of 6

Thread: Trouble with null value in SQL statement

Threaded View

  1. #3
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,229

    Re: Trouble with null value in SQL statement

    What I do is break out that expression into a custom DateToString function which returns NULL or your quoted value.

    edit:

    Code:
    Private Function DateToString(ByVal DateExpr As Variant) As String
        If IsNull(DateExpr) Then
            DateToString = "NULL"
        Else
            DateToString = Replace("TO_DATE('{0}','MM/DD/YYYY')", "{0}", Format(DateExpr, "mm/dd/yyyy"))
        End If
    End Function
    Code:
    strWriteData = "INSERT INTO PROD.CSU_Clinic_Info(ID,Institution,Occurs,Clinic_Date,Location_Num,SID_DOC_NUM," & _
                             "Clinic_Num,Clinic_Code,Doc_Index,Rooms_Used,Time_Of_Day,Cancelled," & _
                             "Cancelled_Reason,Special,Hold,Reassignment,Day_Of_Week,Reinstate,Start_Date,End_Date,User_Name,Special_Booked_Date) " & _
                             "VALUES ('" & mUniqueID & _
                             "','" & mInstitution & _
                             "','" & mOccurs & _
                             "'," & DateToString(mClinic_Date) & _
                             ",'" & mLocation & _
                             "','" & mSID_DOC_NUM & _
                             "','" & mClinicNum & _
                             "','" & mClinic_Code & _
                             "','" & mDoc_Index & _
                             "','" & mRooms & _
                             "','" & mtime & _
                             "','" & mCancelled & _
                             "','" & mCancelledReason & _
                             "','" & mSpecial & _
                             "','" & mHold & _
                             "','" & mReassignment & _
                             "','" & mDayOfWeek & _
                             "','" & mReinstatement & _
                             "'," & DateToString(mStart_Date) & _
                             "," & DateToString(mEnd_Date) & _
                             ",'" & mUserName & _
                             "'," & DateToString(mSpecialBookedDate)

    conversion from date to string back to date seems very very wrong...
    Last edited by DEXWERX; Apr 11th, 2017 at 10:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width