Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:15:27+00:00 2026-06-17T13:15:27+00:00

I am trying to run a query for a custom report that is supposed

  • 0

I am trying to run a query for a custom report that is supposed to return data for clients that match five criteria based on loan repayment types within a specified date range. The criteria are Salary Deduction, Bank Standing Order, Self-Pay, Post Dated Cheques and Bank Debit. The results should return a count of the number of clients from each criteria specified. However, that is not the results I am currently getting; these queries are being tested against this software, Mambu. The results depend on a customfield and customfieldvalue (which specifies the repayment type to use) columns. This is how I expect my desired results should look:

++++++++++++++++++++++++++++++++++++++++++++++++++++++
| LoanProduct           | RepaymentType    | Clients |
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| JUMPSTART LOAN WEEKLY | Self-Pay         | 35      |
------------------------------------------------------
| PAYDAY LOAN MONTHLY   | Salary Deduction | 5       |
------------------------------------------------------
| MICRO-BIZ LOAN        | Bank Debit       | 26      |
------------------------------------------------------
| PAYDAY LOAN WEEKLY    | Self-Pay         | 1       |

  .......
and so on ...

Solutions that I’ve tries so far:

QUERY #1:
For this query I’m just trying to get back all the clients without a count for a specific repayment type; it works for that scenario.

SELECT CONCAT(client.FIRSTNAME, ' ', client.LASTNAME) AS Client, 
    CONCAT(user.FIRSTNAME, ' ', user.LASTNAME) AS Originator, 
    loanproduct.PRODUCTNAME AS LoanProduct, customfieldvalue.VALUE AS RepaymentType
FROM client, user, customfieldvalue, loanaccount
INNER JOIN loanproduct ON loanaccount.PRODUCTTYPEKEY = loanproduct.ENCODEDKEY 
WHERE client.ASSIGNEDUSERKEY = user.ENCODEDKEY 
    AND loanaccount.ACCOUNTHOLDERKEY = client.ENCODEDKEY
    AND customfieldvalue.VALUE = "Bank Debit"
    AND loanaccount.DISBURSEMENTDATE BETWEEN "2012-01-01" AND "2013-01-31"
GROUP BY user.LASTNAME, client.LASTNAME

QUERY #1.1
Adding an OR to the above produces no results:

SELECT CONCAT(client.FIRSTNAME, ' ', client.LASTNAME) AS Client, 
    CONCAT(user.FIRSTNAME, ' ', user.LASTNAME) AS Originator, 
    loanproduct.PRODUCTNAME AS LoanProduct, customfieldvalue.VALUE AS RepaymentType
FROM client, user, customfieldvalue, loanaccount
INNER JOIN loanproduct ON loanaccount.PRODUCTTYPEKEY = loanproduct.ENCODEDKEY 
WHERE client.ASSIGNEDUSERKEY = user.ENCODEDKEY 
    AND loanaccount.ACCOUNTHOLDERKEY = client.ENCODEDKEY
    AND customfieldvalue.VALUE = "Bank Debit" OR customfieldvalue.VALUE = "Self-Pay"
    AND loanaccount.DISBURSEMENTDATE BETWEEN "2012-01-01" AND "2013-01-31"
GROUP BY user.LASTNAME, client.LASTNAME

QUERY #2
I even tried doing this using a CASE statement, but it only returns all the rows for Clients as NULL and takes ~12.1 seconds to complete.

SELECT
    loanproduct.PRODUCTNAME AS LoanProduct, customfieldvalue.VALUE AS RepaymentType,
    CASE
       WHEN customfieldvalue.VALUE = "Salary Deduction" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
       WHEN customfieldvalue.VALUE = "Bank Standing Order" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
       WHEN customfieldvalue.VALUE = "Self-Pay" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
       WHEN customfieldvalue.VALUE = "Post Dated Cheques" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
       WHEN customfieldvalue.VALUE = "Bank Debit" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
    END AS Clients
FROM client, user, customfieldvalue, loanaccount
INNER JOIN loanproduct ON  loanaccount.PRODUCTTYPEKEY = loanproduct.ENCODEDKEY
WHERE client.ASSIGNEDUSERKEY = user.ENCODEDKEY
    AND loanaccount.ACCOUNTHOLDERKEY = client.ENCODEDKEY
    AND loanaccount.DISBURSEMENTDATE BETWEEN "2012-01-01" AND "2013-01-31"
GROUP BY user.LASTNAME, client.LASTNAME

What am I doing wrong here, which is preventing me from getting my desired results? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:15:29+00:00Added an answer on June 17, 2026 at 1:15 pm

    For query 2, you need to add parentheses, or use in syntax:

    AND customfieldvalue.VALUE in ('Bank Debit', 'Self-Pay')
    

    As important as getting the where syntax right is fixing the join syntax in the from clause:

    FROM client join
         user
         on client.ASSIGNEDUSERKEY = user.ENCODEDKEY join
         loanproduct
         ON loanaccount.PRODUCTTYPEKEY = loanproduct.ENCODEDKEY and
            loanaccount.ACCOUNTHOLDERKEY = client.ENCODEDKEY CROSS JOIN
        customFieldValue
    where loanaccount.DISBURSEMENTDATE BETWEEN "2012-01-01" AND "2013-01-31" and
          customfieldvalue.value in ('Bank Debit')
    

    Gosh, you would see right away that something is probably wrong. You usually don’t want to be cross joining tables in a well designed data warehouse. How is CustomFieldValue connected to the other tables?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run a query that will return rows sorted by closest to
I want to run a linq query that will return values to my custom
In Silverstripe 3, I'm trying to run some custom SQL and return the result
I'm trying to run a query that checks if some conditions are true and
I am trying to run this query LOAD DATA CONCURRENT INFILE 'C:\\Data-API.csv' INTO TABLE
I am trying to run a query to update the value of a custom
I'm trying to run a query on Rally using an Excel plugin based on
So I am trying to run a query that will select, in this case,
I'm trying to run a query that has a few columns that are a
I am trying to run a query that essentially looks like this: INSERT INTO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.