Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best Way To Do This
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01520112
Message ID:
01520177
Views:
44
>Here's what I used, and it worked fine.
>
>
>USE Indiana_ODS_VT
>/*
>SELECT TOP 100 * FROM FarmersImport
>SELECT TOP 100 * FROM tblCamp_CT_Kevin
>*/
>
>
>UPDATE tblCamp_CT_Kevin SET Farmer = NULL
>SELECT @@ROWCOUNT
>-- Returns 696397
>
>BEGIN
> 
>    BEGIN TRANSACTION
> 
>    UPDATE tblCamp_CT_Kevin SET Farmer = '1'
>		FROM tblCamp_CT_Kevin c
>		INNER JOIN FarmersImport fi ON LTRIM(RTRIM(fi.[FirstName])) = LTRIM(RTRIM(c.FName)) AND
>									   LTRIM(RTRIM(fi.[LastName])) = LTRIM(RTRIM(c.LName)) AND
>									   LTRIM(RTRIM(fi.[RegCity])) = LTRIM(RTRIM(c.City))
>		WHERE c.Farmer IS NULL
>
>	SELECT @@ROWCOUNT
>
>--39604 with MailCity
>--39701 with RegCity
>
>    IF @@ROWCOUNT = 0
>      BEGIN
>        COMMIT TRANSACTION
>      END
>	ELSE
>      BEGIN
>        ROLLBACK
>      END
>
> END
><pre>
>
>Thanks everyone


Kevin,
The whole code above could be write like this:
<Pre>
UPDATE tblCamp_CT_Kevin SET Farmer = '1'
       FROM tblCamp_CT_Kevin c
INNER JOIN FarmersImport fi ON LTRIM(RTRIM(fi.[FirstName])) = LTRIM(RTRIM(c.FName)) AND
                               LTRIM(RTRIM(fi.[LastName]))  = LTRIM(RTRIM(c.LName)) AND
                               LTRIM(RTRIM(fi.[RegCity])) = LTRIM(RTRIM(c.City))
WHERE ISNULL(c.Farmer,0) = 0
The whole point of the update by smaller pieces of records is that this approach sometime is faster than update the whole table at once.
But, of course, this is your choice.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform