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

  • Home
  • SEARCH
  • 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 7520817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:08:00+00:00 2026-05-30T02:08:00+00:00

I have an SP which needs to be executed as many times as i

  • 0

I have an SP which needs to be executed as many times as i find rows in a temporary table (Just like insertion using a select statement)

My table @OutMessageQIDs has id column (with say 10 rows)
The SP HL7_InsertComponentLog requires 5 parameters as following

EXEC [HL7_InsertComponentLog] --@iPraID,@iComponentID,@vComponentType,'Send',id
SELECT @iPrcID,@iComponentID,@vComponentType,'Send',id
FROM @OutMessageQIDs

Can i do it without using Cursor or Loop kind of thing?

EDIT 1: a little more explanation – @OutMessageQIDs is a temporary table storing the ids of items Queued in a QueueTable (in an SP). and the SP HL7_InsertComponentLog logs the Queue-ed items. Depending upon @vComponentType, it logs different type of data.

EDIT 2: SP is as :

Create Procedure [dbo].[HL7_InsertComponentLog]
    @IPracID [int],
    @iComponentID [bigint],
    @vComponentType varchar(50),
    @vStatus varchar(200),
    @iOutMessageQueueID [bigint]
AS
    select* from hl7_outmessagelog

    IF @vStatus != 'Success'
    BEGIN
        SELECT -1
    END
    ELSE IF @vComponentType = 'LabOrder' OR @vComponentType = 'ProcedureOrder' OR @vComponentType = 'RadiologyOrder' 
    BEGIN 
        SELECT -1
    END
    ELSE IF @vComponentType = 'LabResult' OR @vComponentType = 'ProcedureResult' 

    BEGIN       
        INSERT INTO OrderResult_Addendum (iOrderDetailID,IUserID,DateTime_Stamp,iType,VchComments,iOrderID,iPracID,vAction,bAcknowledge)
                                SELECT   NULL,0,dTimeStamp,NULL,NULL,@iComponentID,@iPracID,@vStatus,0
                                FROM HL7_OutMessageQueue Q 
                                WHERE Q.iOutQueueID = @iOutMessageQueueID and iPracID = @iPracID
    END
    ELSE IF @vComponentType = 'RadiologyResult'
    BEGIN 
        INSERT INTO OrderResult_Addendum (iOrderDetailID,IUserID,DateTime_Stamp,iType,VchComments,iOrderID,iPracID,vAction,bAcknowledge)
                                SELECT   iOrderDetailID,0,Q.dTimeStamp,NULL,NULL,@iComponentID,@iPracID,@vStatus ,0
                                FROM HL7_OutMessageQueue Q 
                                INNER JOIN OrderResultDetails det ON Q.iComponentID = det.iOrderID
                                WHERE Q.iOutQueueID = @iOutMessageQueueID and Q.iPracID = @iPracID
    END
    ELSE IF @vComponentType = 'ClinicalNotes' 
    BEGIN       

        INSERT INTO Note_provider_encounter(iReportID,iUserID,iComponentID,dEncounterDate,vaction)
                                    SELECT  @iComponentID,0,0,dTimeStamp,@vStatus 
                                    FROM HL7_OutMessageLog Where iOutMessageLogID = @iOutMessageQueueID and iPracID = @iPracID
    END 
    ELSE IF @vComponentType = 'PatientDemo' 
    BEGIN       
        DECLARE @IPatID int
        DECLARE @IUserID int
        SELECT @IPatID = iPatID,@IUserID = iUserID
        FROM HL7_OutMessageQueue Q 
                                WHERE Q.iOutQueueID = @iOutMessageQueueID and iPracID = @iPracID
        EXEC [dbo].[InsertPatientLog] @IPracID,@IPatID,@vStatus,@IUserID
    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-05-30T02:08:01+00:00Added an answer on May 30, 2026 at 2:08 am

    No you can’t EXEC a stored procedure for each row in a table without using a loop of some kind.

    What does your stored procedure do? It may be possible to extract the logic from that and perform it in a set based manner against the whole table.

    e.g. Just use

    INSERT INTO ComponentLog
    SELECT @iPrcID,@iComponentID,@vComponentType,'Send',id
    FROM @OutMessageQIDs
    

    instead of calling the stored procedure for each row.

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

Sidebar

Related Questions

I have code which needs to do something like this There is a list
I have a table which needs to link one of three seperate tables, but
I have an application in VC++ which needs to execute a function provided to
I have an interface method public void Execute(ICommand command); which needs to pass known
I have application which needs to use a dll (also written by me) which
We have an application which needs to use Direct3D. Specifically, it needs at least
I have a program which needs to behave slightly differently on Tiger than on
I have some code which needs to ensure some data is in a mysql
I have a program which needs installing on windows 64 boxes. Most of the
I have an application which needs to loop through all the lines in text

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.