Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best Way To Do This
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01520112
Message ID:
01520142
Vues:
41
>>>I have a table of voter info called Farmers with 92K rows in it. I also have a table of voters called tblCamp_CT with 9 million rows. I added a column to tblCamp_CT called 'IsFarmer' TINYINT.
>>>
>>>I now need to go through the Farmers table and for every row find the person in the tblCamp_CT using First Name, Last Name, Middle Name, and maybe some other info. If that person exists in the tblCamp_CT table, then set IsFarmer to 1.
>>>
>>>Wat's the best way to do something like this?
>>
>>
>>WHILE (2 > 1)
>>  BEGIN
>>    BEGIN TRANSACTION
>>    UPDATE TOP ( 10000 ) tblCamp_CT SET isFarmer = 1
>>    FROM tblCamp
>>    INNER JOIN Farmers ON ....
>>    WHERE  tblCamp.isFarmer = 0
>>    
>>    IF @@ROWCOUNT = 0
>>      BEGIN
>>        COMMIT TRANSACTION
>>        BREAK
>>      END
>>    COMMIT TRANSACTION
>>  END -- WHILE
>>
>
>Ok, thanks. I was thinking of using SSIS, but this works for me.

I suggest to use SSIS for this problem. If we want to use loop in T-SQL, we can add another column to Farmers table and then our loop will be

update top (1000) ...
OUTPU Inserted.FirstName, Inserted.LastName, .... into @TempResult

UPDATE Farmers set Processed = 1
inner join @TempResult T ...


In other words, we need to not process the same records over and over again and for this reason I only see a double update way.

Alternative solution will be to try to update all 92K records - this may be very slow.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform