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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 multiple updates on table

Author  Topic 

spiveygb
Starting Member

3 Posts

Posted - 2007-10-31 : 13:24:50
I need to update information for a user and if the user is classified as a primary (@blnPrimary) then I need to update information for all users within his agency (AgencyUniqueId). The issue is that the second UPDATE to "cdds_User_Profile" always returns a rowcount of 0 (should be 1) even though the values for "@Original_AgencyUniqueId" and "@Original_UserId" are correct. This is just a snippet of the whole procedure. I'm trying to implement similar logic in other parts of the procedure and I'm observing the same behavior there as well. Any help anyone can provide is greatly appreciated.


/*** Update User Profile ***/
UPDATE [cdds_User_Profile]
SET [FirstName] = @FirstName, [LastName] = @LastName, [Title] = @Title,
[Phone] = @Phone, [AcctType] = @AcctType, [AcctStatus] = @AcctStatus,
[LastUpdatedDate] = GETDATE()
WHERE ([FirstName] = @Original_FirstName AND [LastName] = @Original_LastName
AND [Title]=@Original_Title AND [Phone]=@Original_Phone
AND [AcctType]=@Original_AcctType AND [AcctStatus]= @Original_AcctStatus
AND [AgencyUniqueId] = @Original_AgencyUniqueId
AND [UserId] = @Original_UserId);
IF @@ROWCOUNT = 0
BEGIN
SET @err_message = 'Data has been edited by another user since you began viewing this information.'
RAISERROR (@err_message,11, 1)
ROLLBACK TRANSACTION
RETURN
END
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
RETURN
END

IF @blnPrimary = 1
BEGIN
IF LOWER(@AcctStatus) <> LOWER(@AgencyAcctStatus)
/*** Update Users Acct. Status ***/
/* update all users in same agency profile */
UPDATE [cdds_User_Profile]
SET [AcctStatus] = @AcctStatus,[LastUpdatedDate] = GETDATE()
WHERE ([AgencyUniqueId] = @Original_AgencyUniqueId
AND [UserId] = @Original_UserId);
IF @@ROWCOUNT = 0
BEGIN
SET @err_message = 'Data for this agency has been edited by another user since you began viewing this information.'
RAISERROR (@err_message,11, 1)
ROLLBACK TRANSACTION
RETURN
END
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
RETURN
END
END

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-31 : 13:35:54
IF @@ROWCOUNT = 0
BEGIN
...
END
IF @@ERROR <> 0
BEGIN
...
END

will not work - needs to be

select @rowcount = @@rowcount, @error = @@error
IF @rowcount = 0
BEGIN
...
END
IF @error <> 0
BEGIN
...
END


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

spiveygb
Starting Member

3 Posts

Posted - 2007-10-31 : 14:12:49
I've implemented the change you posted. However, I'm still seeing the same behavior of rowcount = 0. Could the first UPDATE still have a lock on when the second UPDATE attempts and that is why it always returns 0?
Go to Top of Page
   

- Advertisement -