Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I still have this problem! How can I duplicate Rows. SomeBody?

Status
Not open for further replies.

FLUZZI

Programmer
Jul 13, 2000
17
0
0
BR
Hi!<br><br>I have a table with this columns:<br><br>ID(identity) QT(Int)<br><br>A need&nbsp;&nbsp;a sql that repeat a row many times is the value &quot;QT&quot; column. Like this:<br><br>ID ¦ QT<br>1&nbsp;&nbsp;¦ 3<br>2&nbsp;&nbsp;¦ 5<br>3&nbsp;&nbsp;¦ 2<br>4&nbsp;&nbsp;¦ 6<br><br>a need a sql with this results:<br>ID<br>1<br>1<br>1<br>2<br>2<br>2<br>2<br>2<br>3<br>3<br>4<br>4<br>4<br>4<br>4<br>thanks in advance and sorry about my english.
 
I'm relatively new at SQL server, but with the code below this seems possible.<br><br><br>Dim x as integer<br>Dim rec<br><br>x=1<br><br>for each rec in
<br><br>&nbsp;&nbsp;&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug.print
.ID<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x=x+1<br>&nbsp;&nbsp;&nbsp;loop while x&lt;
.[QT]<br><br>Next rec<br>
 
One SQL solution - not the prettiest but workable.<br><br>Select ID<br>from YourTable INNER JOIN #Number ON Integer &lt;= QT<br><br>where #Number is simple temp table with consecutive integers starting at 1 going as high as you need.<br> <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
You have to turn on the IDENTITY_INSERT on that Table and the command is<br><br>&nbsp;SET IDENTITY_INSERT &lt;table&gt; ON<br><br>and then insert the rows. Normally IDENTITY automatically inserts a running sequence number. When IDENTITY_INSERT is off then it will not allow you to insert any value into this column.<br><br>I do not know where and how you use this. If this a stored procedure then add this statement in. If not then you may have to execute this statement prior to inserting data <br><br>For instance, execute this sql statement in vb first and then insert row within the same session.<br><br><br>Regds<br><br>Subramanian K<br>
 
DreewToo- Yes I try this, but it's to slowly. I Need this is a SQL Statament. Thanks anyway!<br><br>MalcolW- I will try that. Valeu!!( In portuguese means Thanks man! :) )<br><br>Subuk - Ok,but i need this results in other table!Thanks!
 
An interesting string function I just came across that might hold some interest for you is the string() function.<br><br>(From a VBA Tutorial I'm studying at <A HREF=" TARGET="_new"> ...)<br><br>String( )<br>Returns a string composed of a specified number of repetitions of selected characters. <br><br>Example: String(4,&quot;3&quot;) <br>Result: 3333 <br><br>Drew<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top