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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:55:28+00:00 2026-05-15T03:55:28+00:00

I have two stored procedures, the first one calls the second .. If I

  • 0

I have two stored procedures, the first one calls the second ..
If I execute the second one alone it takes over 5 minutes to complete..
But when executed within the first one it takes little over 1 minute..
What is the reason !

Here is the first one

ALTER procedure [dbo].[schRefreshPriceListItemGroups] as

begin tran
delete from PriceListItemGroups
if @@error !=0 goto rolback
Insert PriceListItemGroups(comno,t$cuno,t$cpls,t$cpgs,t$dsca,t$cpru)
SELECT distinct c.comno,c.t$cuno, c.t$cpls,I.t$cpgs,g.t$dsca,g.t$cpru
    FROM    TTCCOM010nnn    C
    JOIN    TTDSLS032nnn    PL  ON  PL.comno    =   c.Comno     and PL.t$cpls   =   c.t$cpls
    JOIN    TTIITM001nnn    I   ON  I.t$item    =   pl.t$item   AND I.comno     =   pl.comNo
    JOIN    TTCMCS024nnn    G   ON  g.T$cprg    =   I.t$cpgs    AND g.comno     =   I.Comno
 WHERE  c.t$cpls !='' 
order by comno desc, t$cuno, t$cpgs
if @@error !=0 goto rolback
-----------------------------------------------------
Exec scrRefreshCustomersCatalogs
-----------------------------------------------------
commit tran


return
rolback:
Rollback tran

And the second one

Alter proc scrRefreshCustomersCatalogs as
declare @baanIds table(id int identity(1,1),baanId varchar(12))
declare @baanId varchar(12),@i int, @n int
Insert @baanIds(BaanId)
select baanId from ftElBaanIds()
SELECT @I=1,@n=max(id) from @baanIds
select @i,@n
Begin tran
if @@error !=0 goto xRollBack
WHILE @I <=@n
    Begin
        select @baanId=baanId from @baanIds where id=@i
        if @@error !=0 goto xRollBack
        Delete from customersCatalogs where comno+'-'+t$cuno=@baanId
        print Convert(varchar,@i)+' baanId='+@baanId
        Insert customersCatalogs exec customersCatalog @baanId
        if @@error !=0 goto xRollBack

        set @i=@i+1;
    end

Commit Tran
Update statistics customersCatalogs with fullscan

Return
xRollBack:
Print '*****Rolling back*************'
Rollback tran
  • 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-15T03:55:29+00:00Added an answer on May 15, 2026 at 3:55 am

    It’s hard to say. When run within the first SP, you will be inside two transactions.

    I assume the second SP does something indirectly with the data insert in the first SP (PriceListItemGroups), so when you are running the second SP by itself, is the same data also insert into that table?

    In the first SP, it also seems odd that you are inserting with an ORDER BY. While I know that’s technically allowed, in almost every case, it’s unnecessary.

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

Sidebar

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.