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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replicate data based on record criteria

Status
Not open for further replies.

cdw0308

Technical User
Oct 8, 2003
181
US
I have a table with

cable_num
cond_num


cable_num is a text field

cond_num is a numeric field

ex.

cable_num cond_num

1AP0001 4
1BA0001 2


I need to make this data converted to:

1AP0001_1 4
1AP0001_2 4
1AP0001_3 4
1AP0001_4 4
1BA0001_1 2
1BA0001_2 2



 
Couple of ways depending on your setup.

This article explains how to use CURSORS and SELECT statements to loop through your table and INSERT the necessary rows. It should flow something like this:

UPDATE current cable_num fields to include the '_1' on the end since they probably will all have at least 1 iteration of cond_num.

Loop through the table finding (cond_num - 1) for each distinct cable_num and then insert that many rows with the increasing cable_num concatenation.


All lessons learned from the School of Hard Knocks........at least tuition is cheap.
 
Can you provide some actual code that could get me started?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top