I have been looking for a simple and reliable way to generate SQL queries which can be executed on several databases. I have a DataFlex Reports report which loads its data with RDS which is retrieved using a query on a DataFlex WebApp. That query is somehow complex but really fast and will retrieve thousands of records instantly. In order obtain that data, we had two options: use some SQL Server specific commands or retrieve that "raw" data and then iterate through it with DataFlex loops and process it (which slowed the process a lot).
Now we need that process to work on Oracle (potentially with more databases) but obviously that SQL Server syntax won't work. Writing If/Elses on that procecess to generate the needed SQL Query is not pretty. I have thought on writing extra functions to perform that syntax conversions so that every query generation process remains untouched, but I haven't much experience with this.
Let me show you what I am thinking:

Code:
Function GenerateSQLQuery Returns String
    // DataFlex SQL Query generation code
    String sSQLQuery

    // SQL Server
    // SELECT NAME, ADDRESS +', '+ CITY AS CUSTOMER_ADDRESS FROM CUSTOMER
    // Oracle
    // SELECT NAME, ADDRESS||', '||CITY AS CUSTOMER_ADDRESS FROM CUSTOMER

   Move ("SELECT NAME, ADDRESS"-ConcatSQLColumns(Self,"ADDRESS","CITY")*"AS CUSTOMER_ADDRESS FROM CUSTOMER") to sSQLQuery

   Function_Returns sSQLQuery
End_Function

Function ConcatSQLColumns String sColumn1 String sColumn2 Returns String
    String sResult sDriver
    
    // Obtain the database driver...
    // Get psDriver of SomewhereFromApplicationCode to sDriver

    Case Begin 
        Case (sDriver="MSSQLDRV")
            Function_Return (sColumn1-"+', '+"*sColumn2)
        Case (sDriver="Oracle")  // ODBC_DRV or something but assuming it is an Oracle Database
            Function_Return (sColumn1-"||', '||"*sColumn2)
        Case Else
            Error DFERR_OPERATOR "Unsupported driver."
    Case_End
End_Function
// With that code, the query generated by GenerateSQLQuery will be executed and the result stored on a matrix. DataFlex Reports RDS report will display that.
This is pseudocode but it might compile, I just wrote it here. I think it can work but I don't know whether it is the best solution for multiple database types supported queries.
Do you have experience with something like this? If that is the case, could you tell me what would you recommend me to do?