RE: insert while

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mal .mullerjannie_at_hotmail.com> (.mullerjannie_at_hotmail.com)
Date: 10/06/04


Date: Wed, 6 Oct 2004 07:43:05 -0700

It always make me happy to see what weird things people accomplish with SQL
and I wonder why... :]

Use another count variable,

Mind pasting all of your while statement ?
Maybe some data as well.

"Darren Woodbrey" wrote:

> I am trying to insert records from a table to the same table. This is my
> query:
>
> declare @counter int
> set @counter = 0
> while @counter < @wo_count
> Begin
> set @counter = @counter + 1
> INSERT INTO wo_audit
> (updateid, TableName, entry, ColumnName, OldValue,
> NewValue, DateModified, domainuser)
> SELECT updateid, TableName, entry + @counter, ColumnName, OldValue,
> NewValue, DateModified, domainuser
> FROM wo_audit
> WHERE (updateid = @updateid)
>
> If there is one entry in my table with updateid = 54 and wo_count = 5, I
> want the record inserted 5 times incrementing the entry column by one. This
> query works except, on the second run through the while loop, there are now
> 2 records with updateid = 54, so it inserts 2, then there are three, so it
> inserts three on the next loop and so on and so on. Is there a way to only
> get the number equal to wo_count to be inserted? Thanks!
>
> Darren
>
>
>



Relevant Pages

  • Re: LOOP WITHIN A LOOP
    ... Assuming you can define a set of forbidden values, a Query is probably the easiest way to go. ... But your criteria could be trickier than just an easily listed set. ... Public Function DataScore(_ ... The reason I asked the loop within a loop question was so that I can loop through all of the fields for each record anh have a running score. ...
    (microsoft.public.access.tablesdbdesign)
  • JDBC: Retaining multiple result sets from a query made in a loop
    ... I'm planning a small Java app using JDBC and have question about making ... My program will make a query once and then use one of the fields from ... Make a single query and get the results in result set RS1 ... This will not work since each trip through the loop destroys the ...
    (comp.lang.java.databases)
  • Re: fiter records in class module
    ... You can run a temporary parameter query from a module. ... allows you to keep changing criteria in a loop. ... For help with creating an SQL string for your database, ... ' See if recordset contains records: ...
    (microsoft.public.access.modulesdaovba)
  • RE: Exporting to Excel
    ... The OpenQuery call in the Loop seems to be critical. ... Static Function GetUserIdAs String ... 'Open the specific query with the data to be exported ... You can use this to drive a loop that will export a worksheet per userid. ...
    (microsoft.public.access.externaldata)
  • Re: Converting from Access to SQL2k via Excel- HELP!!!!!
    ... Then create a new query and paste the following into its SQL ... > In your database you'd need to start with a query that ... The function that you pointed me to allows me to concatenate all ... The problem that I have is that I need to put it into a loop ...
    (microsoft.public.access.conversion)