RE: insert while
From: Mal .mullerjannie_at_hotmail.com> (.mullerjannie_at_hotmail.com)
Date: 10/06/04
- Next message: Manny Chohan: "Replace Null"
- Previous message: Toby Herring: "Re: how to format a money field"
- In reply to: Darren Woodbrey: "insert while"
- Next in thread: Jacco Schalkwijk: "Re: insert while"
- Messages sorted by: [ date ] [ thread ]
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
>
>
>
- Next message: Manny Chohan: "Replace Null"
- Previous message: Toby Herring: "Re: how to format a money field"
- In reply to: Darren Woodbrey: "insert while"
- Next in thread: Jacco Schalkwijk: "Re: insert while"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|