Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have a table with the field content :

item qty
----- -----
tea 2

I want to display as below

item qty
---- ------
tea 1
tea 1

how to create sql query like above ?

thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jan-15 0:23am    
Aren't you joking? :-)
—SA

The question makes no sense. The record with item:"tea" and quantity:2 is not duplicate! This is only one record, and '2' is its attribute, not indication of having two separate records. You cannot get on output of a query something which is not in the table you query.

—SA
 
Share this answer
 
v2
To add to previous solution. You would need a logic to repeat the data desired amount of times. This means that you need yo use Transact-SQL to do the job.

Perhaps the easiest way could be to create a stored procedure which would loop your data (in case you have multiple rows in the table) and then in another loop you would add the rows into the result set desired amount of times.

This could be done in a standard procedure or in a table valued function (for example Using Table-Valued Functions in SQL Server[^])
 
Share this answer
 
sorry if my question is a bit confusing .. thanks for the response ..
I have found the solution click here
 
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