i want to read each row and search for a particular string and store it in a new variable in an existing table using while loop in Stored procedure , how can i do that

K Aravind Kumar 0 Reputation points
2023-01-23T04:33:15.0666667+00:00

Hi ,

i want to search for a particular student_name in a row(i have 150 rows) in an existing Student_Table using while loop in stored procedure and once if a find a student_name then i need to store it in a new variable

Note : student names data varies daily it is not fixed row so dont want to go with hard coding, i need to read Student_Table using while loop.

Thanks,

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,367 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 43,246 Reputation points
    2023-01-23T06:49:52.6033333+00:00

    using while loop

    Why a loop, in SQL we work set-based, not row-wise?

    At all, that's really to less on information.

    Please post table design as DDL, some sample data as DML statement and the expected result.

    0 comments No comments

  2. PercyTang-MSFT 12,426 Reputation points Microsoft Vendor
    2023-01-23T08:37:49.2233333+00:00

    Hi @K Aravind Kumar

    Your description of the problem confuses me, if it's just searching the entire table for specific data, then using

    select * from Student_Table where student_name = '...'
    

    That's enough.

    If you want to store the found data into a new variable, you might use a while loop.

    Please provide more information based on Olaf's recommendations.

    Best regards,

    Percy Tang


    If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments