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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:56:58+00:00 2026-05-24T11:56:58+00:00

I have one general question about optimization at SQL Server: How I can reduce

  • 0

I have one general question about optimization at SQL Server: How I can reduce number of Reads in stored procedure?

I’m interested in good practices like:
– creating indexes at physical and temp tables
– using temp tables instead using same table couple times in procedure
– DDL before DML
– SET NOCOUNT ON at the beginning of stored procedure
– …

We have issue with disk space that is used because of huge number of reads that is caused by couple stored procedures and I need to optimize it.

Part of stored procedure that is ‘the most expensive’ is:

create table #stavke   
(  
    Id_Br int identity(1, 1), IDStavke int, 
    HeaderID int, Currency varchar(3),  GLAcct varchar(20), id varchar(20), Trnuid varchar(60), 
    ReferenceID varchar(20), DocumentID varchar(20),
    DtAvail varchar(10), DtBooking varchar(10), DatePosted varchar(10),
    Amount money, AmountLcl money, 
    Description varchar(250), Type varchar(10), DP int  )
insert into #stavke   
  (  
    IDStavke, HeaderID, GLAcct, Currency, id , Trnuid , 
    ReferenceID, DocumentID ,
    DtAvail , DtBooking , DatePosted,
    Amount , AmountLcl , 
    Description , Type , DP 
  )  

SELECT S.ID as IDStavke,
   z.RB as HeaderID,  
   z.KONTO AS GLAcct,
   z.OZNVAL AS Currency,
   Si.BROJNALOGA as ID,
   D.TRN as Trnuid, 
   case substring(SI.BROJNALOGA,1,4)
        when '0746' then O.REFERENCA
        when '1450' then D.REFERENCA
        when '0743' then L.REFERENCA
        when '2021' then N.REFERENCA
   end   ReferenceID,
   case substring(SI.BROJNALOGA,1,4)
        when '3000' then 'Kursna razlika'
        when '2200' then 'PP-'+SI.BROJNALOGA
        when '2201' then 'KDP-'+SI.BROJNALOGA
        else SI.BROJNALOGA
   end DocumentID,
   dvalute as DtAvail, 
   si.dknizenja as DtBooking, 
   '' as DatePosted,        
   case si.teret
        when 0 then si.korist
        else si.teret 
   end Amount, 
   case SI.DINTERET
        when 0 then si.dinkorist
        else si.dinteret 
   end AmountLcl, 
   '' as Description,
   case substring(SI.BROJNALOGA,1,4)
        when '0746' then '0746'
        when '1450' then '1450'
        when '0743' then '0743'
        when '2021' then  'Ostalo'
   end  Type,
   case SI.DINTERET
        when 0 then 1
        else -1 
   end DP
FROM       A I
inner join B st on i.transfer=st.transfer and i.partija=st.partija 
INNER JOIN C SI ON st.RB=Si.RB
inner join D z on z.rb=st.rb
inner join E s on z.rb=s.rb AND s.BROJNALOGA = si.BROJNALOGA 
LEFT JOIN  F D ON  D.BROJ=SI.BROJNALOGA
LEFT JOIN  G L ON L.BROJ=SI.BROJNALOGA
LEFT JOIN  H O ON O.BROJ=SI.BROJNALOGA
LEFT JOIN  I N ON N.BROJ=SI.BROJNALOGA 
WHERE I.novi_izvod=convert(int,@StatementNumber) AND i.PARTIJA=@Account 
ORDER BY I.PARTIJA,z.RB,SI.id, z.KONTO,z.OZNVAL, SI.DKNIZENJA

Tables B, G, H and I (I changed real names of tables for this example to make it easier for reading) are very big, i.e. have many columns and big amount of data.

  • 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-05-24T11:57:00+00:00Added an answer on May 24, 2026 at 11:57 am

    I hope you are talking of minimizing the disk activity by a procedure.

    firstly, you can benchmark your current IO activity using the

    set statistics IO on;
    

    With that info at hand and getting the Execution Plan with SET SHOWPLAN_ALL or XML or you can make use of ssms to get the same ergonomically. You can make use of DTA for basic tuning.

    Try executing the SP as a bunch of ad-hoc statements and see where the IO is heavy and concentrate on that segment. There are a lot of good practices which might suit your requirement.

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

Sidebar

Related Questions

I have a general question about DB synchronisation. So, I'm developing a website locally
I have a general question about the design of JavaScript Libraries. I am trying
I have a general question about objects, memory, and retaining. I am not a
I have a general question about the way that database indexing works, particularly in
I have a general question about WPF performance. We have a relatively simple forms
So, I have 2 database instances, one is for development in general, another was
I have one text input and one button (see below). How can I use
I have one website on my server, and my IIS Worker Process is using
I have a question about this question . I posted a reply there but
One of our comrades, Peter Mortensen , asked a question on Super User about an

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.