I am in the process of doing my first SQL Server project (version 7), and noticed something that strikes me as odd. Luckily, I have Mike Levy's article on stored procs from the Great Lakes Great Database Workshop. Basically, I am surprised that the following T-SQL statement:
UPDATE Company
SET Price = @Price
WHERE CompanyID = @CompanyID
Does not set @@ERROR
I have to check both @@ROWCOUNT and @@ERROR to see if the update was successful.
Also, right after the UPDATE statement, I cannot get the following to work:
SET @ErrorNo = @@ERROR, @RowCnt = @@ROWCOUNT
Instead, this must be on separate lines:
SET @ErrorNo = @@ERROR
SET @RowCnt = @@ROWCOUNT
The problem is that I think @@ROWCOUNT will be set to 1 after the SET @ErrorNo statement, so even if the UPDATE does not find the @CompanyID, @RowCnt will still be 1.
Chris McCandless
Red Sky Software