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 8299733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:16:14+00:00 2026-06-08T16:16:14+00:00

I’m working on a MVC 3 project where some of the reports will generate

  • 0

I’m working on a MVC 3 project where some of the reports will generate the SQL queries in code then executes them on an Oracle 10g database. Also, I understand SQL injection attacks, and all the values are coming from drop down lists, not text inputs, so this is not an issue. My generated queries “work”, but they are extremely slow. Here is a quick run down on how the report works:

User selected a general ledger account and other filters.
User selected a time period (a fiscal year, a quarter or a specific month).
User runs report.

The report shows the general ledger account (or accounts if the select to show all accounts) and the values spent for each month along with a total for that account. The output from the query will look like this:

Account Number and Name | Month 1 | Month 2 | etc | Total

Month 1, Month 2, etc are dynamically added in while the SQL code is being generated, so depending on what the user selects, it may, or may not, be returned in the result set. What can I do to make this query faster? When I ran this query yesterday for the entire fiscal year (and only 1 account), it took 10mins for it to complete. I don’t feel this is acceptable performance, and would like to make it faster. Keep in mind, I can only make changes to the query itself, not the database, so indexing is not going to happen (the DBAs keep everything locked down). The query is below. Thanks for any input you all can provide on this.

SELECT gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm, bu.bus_unit_txt, gl.gen_led_acct_typ_nm,
  (SELECT SUM(fct.pd_txn_amt) Jun2012
FROM Maintable fct
JOIN Dimtable1 gl1 ON fct.gen_led_acct_key = gl1.gen_led_acct_key
JOIN Dimtable2 bu1 ON fct.bus_unit_key = bu1.bus_unit_key
JOIN Dimtable3 cc1 ON fct.cst_ctr_key = cc1.cst_ctr_key
JOIN Dimtable4 oc1 ON fct.cst_ctr_own_org_key = oc1.org_cd_key
JOIN Dimtable5 dt1 ON fct.chk_dt_key          = dt1.dt_key
WHERE gl1.gen_led_acct_nbr = gl.gen_led_acct_nbr
  AND bu1.bus_unit_txt       = bu.bus_unit_txt
  AND dt1.fscl_mo_nbr        = 1
  AND dt1.fscl_yr_nbr        = 2012
  GROUP BY gl1.gen_led_acct_nbr, gl1.gen_led_acct_scr_nm, bu1.bus_unit_txt) Jun2012,
(SELECT SUM(fct.pd_txn_amt) Jun2012
FROM Maintable fct
JOIN Dimtable1 gl2 ON fct.gen_led_acct_key = gl2.gen_led_acct_key
JOIN Dimtable2 bu2 ON fct.bus_unit_key = bu2.bus_unit_key
JOIN Dimtable3 cc2 ON fct.cst_ctr_key = cc2.cst_ctr_key
JOIN Dimtable4 oc2 ON fct.cst_ctr_own_org_key = oc2.org_cd_key
JOIN Dimtable5 dt2 ON fct.chk_dt_key          = dt2.dt_key
WHERE gl2.gen_led_acct_nbr = gl.gen_led_acct_nbr
  AND bu2.bus_unit_txt       = bu.bus_unit_txt
  AND dt2.fscl_mo_nbr        = 2
  AND dt2.fscl_yr_nbr        = 2012
  GROUP BY gl2.gen_led_acct_nbr, gl2.gen_led_acct_scr_nm, bu2.bus_unit_txt) Jul2012,

(etc...)
--The sub queries above can be repeated up to an indefinite amount of times (maybe 20+), but with a different fscl_mo_nbr (and possibly fscl_yr_nbr as well)

FROM Maintable fct
JOIN Dimtable1 gl ON fct.gen_led_acct_key = gl.gen_led_acct_key
JOIN Dimtable2 bu ON fct.bus_unit_key = bu.bus_unit_key
JOIN Dimtable3 cc ON fct.cst_ctr_key = cc.cst_ctr_key
JOIN Dimtable4 oc ON fct.cst_ctr_own_org_key = oc.org_cd_key
JOIN Dimtable5 dt ON fct.chk_dt_key         = dt.dt_key
WHERE gl.gen_led_acct_nbr = 000000
  AND bu.bus_unit_txt       = 'AAAAA'
  AND dt.fscl_mo_nbr        = 1
  AND dt.fscl_yr_nbr        = 2012
GROUP BY gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm, bu.bus_unit_txt, gl.gen_led_acct_typ_nm
ORDER BY gl.gen_led_acct_nbr, gl.gen_led_acct_typ_nm
  • 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-08T16:16:16+00:00Added an answer on June 8, 2026 at 4:16 pm

    Your comment:

    --The sub query above can be repeated up to another 11 times, but with a different dt1.fscl_mo_nbr
    

    Suggests that one solution would be to use “in” rather than “=”, as in:

    AND dt1.fscl_mo_nbr        in (1, 2, . . . )
    

    You then would want to add t1.fscl_mo_nbr to the group by clause.

    I also notice that this is a big correlated subquery, which is probably also killing performance. Something like the following should simplify the query and help it run faster:

    SELECT gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm, bu.bus_unit_txt, 
           gl.gen_led_acct_typ_nm,
           sum(case when year = 2012 and dt.fscl_mo_nbr = 1 then fct.pd_txn_amt end) as Jun2012,
           sum(case when year = 2012 and dt.fscl_mo_nbr = 2 then fct.pd_txn_amt end) as Jul2012,
            etc. 
          FROM Maintable fct
               JOIN Dimtable1 gl ON fct.gen_led_acct_key = gl.gen_led_acct_key
               JOIN Dimtable2 bu ON fct.bus_unit_key = bu.bus_unit_key
               JOIN Dimtable3 cc ON fct.cst_ctr_key = cc.cst_ctr_key
               JOIN Dimtable4 oc ON fct.cst_ctr_own_org_key = oc.org_cd_key
               JOIN Dimtable5 dt ON fct.chk_dt_key          = dt.dt_key
           where dt.fscl_mo_nbr  in (1, 2, 3 . . .)
                AND dt.fscl_yr_nbr  = 2012
           GROUP BY gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm,
                    bu.bus_unit_txt, dt.fscl_mo_nbr
    

    (Please excuse any typing errors . . . I removed the “1” suffix from all the aliases.)

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT

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.