Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Name Telugu Image price quan

jaen123 ౭౦౦ bcb6a0b-.gif 805 23
tshirt35 ౩౫౦ 9df27e4-.gif 402.5 35
jeans30-32 ౬౦౦ 47d975c-.gif 690 50
jack1 ౮౦౦ 4698ee8-.gif 920 25


i want to display this like


jack1 ౮౦౦ 4698ee8-.gif 920
jack1 ౮౦౦ 4698ee8-.gif 920
jack1 ౮౦౦ 4698ee8-.gif 920
jack1 ౮౦౦ 4698ee8-.gif 920
jack1 ౮౦౦ 4698ee8-.gif 920
jack1 ౮౦౦ 4698ee8-.gif 920 means 25 times

Means row repeat as per the number of quantity
Posted
Comments
Andy Lanng 15-Jun-15 8:56am    
have you use recursive common table expressions before?
Masroor Ansari 15-Jun-15 9:02am    
No
Jörgen Andersson 15-Jun-15 15:42pm    
Which database?

 
Share this answer
 
Comments
Masroor Ansari 15-Jun-15 9:03am    
Not understand
King Fisher 16-Jun-15 0:37am    
let me show wait..
You haven't mentioned which DBMS you're using. Assuming a recent version of Microsoft SQL Server, this is fairly easy to solve.

You'll need a "tally table" - if you don't have one already, there are many ways to generate one. For example:
SQL Wizardry Part Eight - Tally Tables[^]

Once you have that, a simple INNER JOIN will give you the desired result:
SQL
WITH E1 (N) AS 
(
    -- 1*10^1 or 10 rows
    SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1 
    UNION ALL SELECT 1
),
E2 (N) AS 
(
    -- 1*10^2 or 100 rows
    SELECT 1 
    FROM E1 a, E1 b
),
E4 (N) AS 
(
    -- 1*10^4 or 10000 rows
    SELECT 1 
    FROM E2 a, E2 b
),
Tally (N) AS
(
    SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
    FROM E4
)
SELECT
    D.Name,
    D.Telugu,
    D.Image,
    D.price
FROM
    YourTable As D
    INNER JOIN Tally As T
    ON T.N <= D.quan
ORDER BY
    D.Name
;
 
Share this answer
 
v2
Comments
Masroor Ansari 15-Jun-15 10:19am    
Not working
Richard Deeming 15-Jun-15 10:20am    
My psychic powers don't extend to reading your mind, your screen, or your hard-drive.

Define "not working".
Masroor Ansari 15-Jun-15 10:33am    
Not getting my solution

Repeat the same row as quantity times but it not returns
Richard Deeming 15-Jun-15 10:41am    
Try taking out one level from the tally table - see my updated answer.
You can try that.

SQL
create table #InputData (col1 varchar(100), col2 int);
insert into #InputData values('jack1 ౮౦౦ 4698ee8-.gif 920', 25);
insert into #InputData values('jeans30-32 ౬౦౦ 47d975c-.gif 690', 50);
insert into #InputData values('tshirt35 ౩౫౦ 9df27e4-.gif 402.5', 35);
insert into #InputData values('jaen123 ౭౦౦ bcb6a0b-.gif 805', 23);

Declare RestCursor cursor for select col1, col2 from #InputData;
Declare @Col1 varchaR(100);
Declare @Col2 int;
Declare @Count int;

create table #ResultTable (col varchar(100));
open RestCursor;
fetch next from RestCursor into @Col1, @Col2;

while @@FETCH_STATUS = 0 begin
    set @Count = 0;
    while @Count < @Col2 begin
        insert into #ResultTable values(@Col1);
        set @Count = @Count + 1;
    end;
    fetch next from RestCursor into @Col1, @Col2;
end;
close RestCursor;
deallocate RestCursor;

select * from #ResultTable;

drop table #ResultTable;
drop table #InputData;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900