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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:13:31+00:00 2026-06-13T21:13:31+00:00

How can I decrease the execution time with this sql squery? it is taking

  • 0

How can I decrease the execution time with this sql squery? it is taking over a minute to execute and return rows.(executed in Sql server management studio 2008)

if(@NotInvoiced =1)
BEGIN
Select @Command = 
'select Distinct C.FileID, C.FileName, convert(nvarchar,C.DateReported,111) AS ''DateReported'', 
C.FileDetailsPlainText, CFIT.Level3 as ''InvestigationType'', INV.FName + '' '' + INV.LName AS ''Name'', 
convert(nvarchar,DD,111) AS ''DD'', i.FirstName + '' '' + i.LastName AS ''ReportedBy''
from CaseFiles C 
join InvestigatorCaseFileAccess IA on C.FileID=IA.CaseFileID 
LEFT OUTER JOIN CaseFileTimeBills tb on C.FileID=tb.FileID
LEFT OUTER JOIN CaseFileExpenses e on C.FileID=e.FileID

left join Element07a_Persons i on i.PersonID = c.PersonID
LEFT OUTER JOIN CaseFileInvestigationTypes CFIT ON C.InvestigationTypeID = CFIT.InvestigationTypeID 
LEFT OUTER JOIN Investigators INV ON C.InvestigatorID = INV.InvestigatorID
where (tb.InvNumber IS null OR e.InvNumber IS null) and Deleted=0 and IA.InvestigatorID=' + CONVERT (nvarchar(max),@InvestigatorID) + ' and IA.AllowAccess = ''True''
 and tb.FileID = C.FileID or e.FileID=C.FileID '
END
  • 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-13T21:13:33+00:00Added an answer on June 13, 2026 at 9:13 pm

    As we discovered in the comments, it looks like your problem was that you were missing parentheses around tb.FileID = C.FileID or e.FileID=C.FileID.

    Adding those parentheses fundamentally changes the filtering semantics and therefore changes the data you get back. It’s like your original query without the parentheses was returning gobs of data, or at the very least comparing every single possible row when it only needed to compare a few.

    Marlin Pierce made the good observation that parenthesizing those ORs allows the DBMS to use utilize indices (for example for the condition Deleted=0), whereas before it could not.

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

Sidebar

Related Questions

How i can Decrease the report file Loading Time? I Use this Code to
There are certain algorithms whose running time can decrease significantly when one divides up
How can I increase/decrease the default dojo datagrid font size? Should I do this
Are there any javascripts or other method which can decrease loading time of google
How to use RSL(Runtime shared library) in flex ? how can decrease loading time
I need a priority queue where I can increase or decrease the priority key.
When you surf with your browser, you can increase or decrease the font dimension
I am trying to increase or decrease the displayed texts font. but can only
Could someone please provide some suggestions on how I can decrease the following for
I have Following Tables in SQL Server Database: (1) StudentMaster (StudentId, StudentName) (2) SubjectMaster

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.