How to implement a while loop in SQL server based on the below condition.
Then I need to execute select statement which returns ITEM_CODE ,It may have multiple rows too.
What I want to do inside the while loop is for each ITEM_CODE I need to get data from other tables (including joins ) and insert those data to a table .This loop will get end the count based on the first statements return.
Sample query structure:
SELECT ITEM_CODE //While loop must execute the count of this rows
FROM 'TABLE_1'
WHERE ITEM_AVAILABILITY = 'TRUE'
This statement will return a single row or may return multiple rows . I need to pass this ITEM_CODE to the while loop each time .Inside the while loop I will get the values from multiple tables and insert it to another table.
WHILE (@COUNT <>0){
//Need to have the ITEM_CODE while looping each time.
//Get data from multiple tables and assign to variables (SET @VARIABLES)
//Insert statement
IF (@COUNT = @COUNT)
BREAK;
}
Is it possible with SQL server ,If Yes,please help me to fix this .