The correct way to do this is temp table + cursors:
- create a temp table
- create cursor to iterate through Product table
- within the cursor, create an inner WHILE loop
- exit the loop and finally select the temp table
The following isn't 100% correct Sybase syntax, but it's pretty close.
-- 1: temp table
select productName into #TEMP
-- 2: cursor
declare
@productName char(10),
@quantity int
declare ProductRead CURSOR for
select
productName,
quantity
from
Product
OPEN ProductRead
FETCH ProductRead
INTO
@productName,
@quantity
WHILE (@@sqlstatus=0)
BEGIN
-- 3: inner for loop
DECLARE @i INT
SET @i = 1
WHILE @i <= @quantity
BEGIN
insert @productName into #TEMP
END
END
-- 4: final result set
select productName from #TEMP