By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


check_include - udf db implements sql include logic

The purpose of the Check_Include code was to extend SQL by supporting an < include statement >. This statement allows for the sharing of SQL code without repeating it in different files.

The original usage of this and project will be to Generate PowerPoint slides from a database.

The SQL to run will be stored in a file and can use the include statement to minimize duplicate coding


Function check_include(s, sSQLFile)
retry_it:
lStart = instr(s,"
If lStart > 0 then
    lStart = lStart + Len("    lEnd = instr(lStart, s, ">")
    if lEnd = 0 then
        Check_include = s
        Exit Function
    Else
        sFile = Mid(s, lStart + 1, lEnd - (lStart + 1))
        If instr(sFile, ",") > 0 then
            a = Split(sFile,",")
            sFile = a(0)
            parm = a(1)
            parm_replace = "," & parm
        Else
            parm = ""
            parm_replace = ""
        End if
        sRemove = ""
        if dir(sFile) = "" then
            msgbox "error msg"
            End_it
        End if
        sData = " -- This code snippet is from " & sFile & " " & vbCRLF & LoadData(sFile) & " -- end of include ==================== " & vbcrlf
        s = Replace(s, sRemove, " " & sData & " ")
        s = Replace(s, "$cob_date", "'" & Format(Range("cur_month_end"), "yyyy-mm-dd") & "'")
        s = Replace(s, "$parm", parm)
    End if
Else
    check_include = s
    exit function
end if
DoEvents
Goto retry_it

End Function