Need help in iterating one loop inside another while loop in sql procedure

Mohammed Muntazim 21 Reputation points
2022-10-26T08:21:12.297+00:00

ALTER PROCEDURE [cmn].[InsertXMLOutputConfig]
(

@P_DataSubject NVARCHAR(5),
@P_DRS NVARCHAR(10),
)
//i need help in iterating one while loop inside another while loop
//@P_DataSubject value is support 'as,ds,re,tr'
//@P_DRS value is suppose 'hrr,yte,ytw'
//@P_DataSubject i want to put in parent while loop and @P_DRS in child while loop

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

3 answers

Sort by: Most helpful
  1. Sreeju Nair 12,666 Reputation points
    2022-10-26T08:26:50.657+00:00

    Are you looking for guidence in implementing nested loop, I mean a loop inside another. If yes, refer the following tutorial.

    https://www.tutorialgateway.org/nested-sql-while-loop/

    Hope this helps


  2. Jingyang Li 5,896 Reputation points Volunteer Moderator
    2022-10-26T16:47:18.987+00:00

    You may be able to write your nested loops to solve your problem but it is not the right way to do so.
    Think about your issue with nested loops in pseudo-code and implement a SET-based solution in your stored procedure.
    If you need more assistance, you can provide more information and sample data and expected result.

    0 comments No comments

  3. Tom Phillips 17,771 Reputation points
    2022-10-26T17:53:52.663+00:00

    You normally do not want to "loop" in SQL Server.

    Can you explain more about what exactly your proc is expected to do?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.