Forum Discussion

Brooks's avatar
Brooks
New Contributor III
3 days ago
Solved

SQL in BR gets syntax errors, but runs from Data Adapter

Has anybody seen this error?  If so, how did you fix it? I can run the SQL query in question from a Data Adapter just fine, but when trying to run it from a BR I get the above error.  At this ...
  • Brooks's avatar
    Brooks
    2 days ago

    I just figured out the answer to my own question, as you were typing your response.  Thank you for responding.  As it so happens, you cannot have any spaces at the end of a line when calling the SQL from a business rule with Progress, nor can you have comments.  This is different from other SQL databases.
    With most SQL I can do this:
    sqlQuery.Append(" SELECT                                                                                                      ")
    sqlQuery.Append("    GL.GLCode AS Account,                                                                                    ")
    sqlQuery.Append("    IFNULL(CostCentre.CostCentreCode,'') AS CostCenter,                                                      ")
    sqlQuery.Append("    --CAST(IncomeStatement.OpeningBalance AS DECIMAL(38, 2)) AS OpeningBalance,                              ")
    sqlQuery.Append("    --CAST(IncomeStatement.PeriodActivity AS DECIMAL(38, 2)) AS PeriodActivity,                              ")
    sqlQuery.Append("    CAST((IncomeStatement.OpeningBalance + IncomeStatement.PeriodActivity) AS DECIMAL(38, 2)) AS Balance     ")
    imagine that this window is wide enough that the end ") all line up vertically.

    With Progress I can only do this:
    sqlQuery.Append(" SELECT")
    sqlQuery.Append("    GL.GLCode AS Account,")
    sqlQuery.Append("    IFNULL(CostCentre.CostCentreCode,'') AS CostCenter,")

    The closing brackets must be right up against the end of the line.  It is a bit harder on the eyes.

    I prefer the former because it is easier to extract the SQL and put it into a data adapter to monkey with if you want to experiment, but c'est la vie.