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

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,095 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,580 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Sreeju Nair 12,026 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,891 Reputation points
    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,716 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