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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:56:56+00:00 2026-06-02T18:56:56+00:00

In my stored procedure I’m using #temptable to fetch the data from one table

  • 0

In my stored procedure I’m using #temptable to fetch the data from one table and updating that #temptable for result. In my production environment this stored procedure is consuming a lot of time which is causing timeouts at times but in lower environment this query works absolute perfect.

 CREATE TABLE #TempTable
 (
  ID int IDENTITY PRIMARY KEY,
  TOTALPOLICY nvarchar(14),
  SYMBOL nvarchar (3),
  POLNUM nvarchar (7),
  MODULE nvarchar (2),
  LOC char (2),
  MCO char (2),
  LOB char (3),
  INSUREDNAME nvarchar (100),
  TotalPremium decimal (10,2),
  ServiceCharges decimal (10,2),
  TotalPaid decimal (10,2),
  TotalRefunded decimal (10,2),
  CurrentBalance decimal (10,2),
  TotalBilled decimal (10,2),
  PCO char (2)
 )

INSERT INTO #TempTable (TOTALPOLICY,SYMBOL, POLNUM, MODULE, LOC, MCO, LOB, INSUREDNAME,TotalPremium, ServiceCharges, TotalPaid, TotalRefunded, CurrentBalance, TotalBilled, PCO) --PCR 109 SMT added PCO
       EXEC(@sql)

--PCR 109 Start SMT
Update #TempTable 
    Set TotalPaid = IsNull((Select sum(PaymentAmt) 
    From SHCashActivity with (nolock)
Where #TempTable.POLNUM = PolicyNbr 
      and #TempTable.Module = PolicyModuleNbr 
      and #TempTable.Symbol = PolicySymbolCd 
      and CashActivityTypeCd in ('P', 'C', 'N') 
      and CashAppliedStatusCd in ('1','2')), 0) 

Please advise me what could be solution for this .

  • 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-02T18:56:57+00:00Added an answer on June 2, 2026 at 6:56 pm

    The problem is not the temp table. The problem is the process takes too long. Re-architect your process so an answer is generated in a more acceptable length of time.

    Also, your update statement is hard to read. It is also vulnerable to breaking if a field is added to SHCashActivity/#TempTable that matches the name of a field in the other table. Create table alias-es and use them for all field access.

    Also,
    create index X on #TempTable (POLNUM, Module, Symbol)
    will help. The correct order of the fields in the index will depend upon indexes on SHCashActivity.

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

Sidebar

Related Questions

I have a stored procedure that is updating a very large table (with over
i am running a stored procedure to delete data from two tables: delete from
I am using a stored procedure with a prepared statment to find rows from
A stored procedure that runs a SELECT on a large table is timing out.
I've a stored procedure that does something like this: SELECT Id INTO #temp FROM
One Stored procedure returning multiple result sets and I need only the last result
I have written stored procedure to poll the data from the database in biztalk.but
My stored procedure is called as below from an SQL instegartion package within SQL
In a stored procedure, when is #Temptable created in SQL Server 2005? When creating
Scenario: A stored procedure receives from code a DateTime with, let's say DateTime.Now value,

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.