Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-04-20 : 07:48:10
|
| john writes "I am performing the following query on a table with 37,000 records. Each time I run the query, the query stops after 32,736 rows. I tried this 5 times and also checked the value of the range and it is OK. Any help would be appreciated.Thanksdeclare @NEXTOID int, @REFILL bit, @OIDPOOL int declare @i bigint;declare @RC bigint;declare @NOID bigint;Set @i=0SET @NEXTOID=1000000SET @RC = 37000set @NOID = @NEXTOID Declare mycursor cursor for select * from FacelessWorkers1 Open myCursorPRINT @RC FETCH NEXT from mycursor while @i < @RC Begin SET @NOID = @NOID+1 Print @i Print @NOID Update FacelessWorkers1 set OID=@NOID where current of mycursor SET @i = @i+1 FETCH NEXT from mycursor ENDCLOSE mycursordeallocate mycursor" |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2005-04-20 : 12:14:38
|
| 1. stay away from cursors...bad news.2. stay further away from cursors...continue to be bad news....(search here for loads of reasons)You should be able to rewrite this using a set-based technique.Do the following confirm your initial statements?SELECT count(*) from facelessworkers1SELECT count(*) from facelessworkers1 where OID <> 0 |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-04-20 : 17:38:34
|
Will this do it for you?--Assuming facelessworkers1_ID is the primary key of table facelessworkers1.create table #temp(facelessworkers1_ID int not null primary key clustered,New_OID int not null identity(1000001,1)) -- Load #temp table with primary key values and identy values-- starting from first new OIDinsert into #temp ( facelessworkers1_ID )select facelessworkers1_IDfrom facelessworkers1order by facelessworkers1_ID-- Update OID with values in #temp tableupdate facelessworkers1set OID = New_OIDfrom facelessworkers1 join #temp a on facelessworkers1.facelessworkers1_ID = a.facelessworkers1_ID CODO ERGO SUM |
 |
|
|
|
|
|