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

Mohammed Muntazim 21 Reputation points

ALTER PROCEDURE [cmn].[InsertXMLOutputConfig]

@P_DataSubject NVARCHAR(5),
//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
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

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

    Hope this helps

  2. Jingyang Li 5,891 Reputation points

    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

    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