I have a while loop I run to loop through an insert statement. I insert records as long as the integer value inside one of the columns (COMPONENT_QTY) is greater than > 1.
Problem im having is that im using a left join to insert only records into the table whcih dont already exist. Now when I loop through the first time, it inserts the first record, but it doesnt insert the second (3rd, 4th, 5th, 6th, so on....) time because it detects the left join and says oh this record already exists so no more insert.
How do I work around this? TSQL Below:
asked Feb 11, 2010 at 01:10 PM in Default
It seems to me that you either do want to insert records that already exist, or you don't. Decide which is which, then remove / keep the
However, have you considered doing this with a Tally table rather than a while loop? It's a bit difficult to see the logic going on, but you could join to a tally table where the number was between 1 and
And that would presumably make the problem you're asking come out in the wash...
answered Feb 11, 2010 at 01:22 PM
Matt Whitfield ♦♦
I'm struggling to picture the database structure in my head. Would it be possible to provide a structure and then I could help you more.
answered Feb 11, 2010 at 03:42 PM