Chapter 6 PROGRAMMING SQL SERVER 2000 343 If

Chapter 6 PROGRAMMING SQL SERVER 2000 343 If this value returns 128, then the flag was previously set, and ARITHIGNORE is turned on. If the value returns 0, then the flag was not set, and ARITHIGNORE is turned off. Other values that use this are the status value in the sysdatabases table and the status value in the sysobjects table. Using @@ROWCOUNT What s the fuss with @@ROWCOUNT? It just returns the number of rows affected by the previous statement. Well, it can be a bit more complex than that. What would this do? UPDATE mytable SET emptype = manager PRINT all done PRINT @@ROWCOUNT This returns 0. Why? The PRINT statement does not change any rows. As a matter of fact, PRINT statements never return rows. If you want to use a rowcount, you must use it immediately after the row from which you want to pull the data. The following code doesn t work the way you d expect, either: BEGIN TRANSACTION UPDATE mytable SET emptype = manager COMMIT TRANSACTION print @@ROWCOUNT The COMMIT TRANSACTION does not change or select any rows, so there s a zero value in @@ROWCOUNT. You ll learn more about BEGIN TRANSACTION and COMMIT TRANSACTION a little later in this chapter. Now imagine that you are working on finishing your great masterpiece batch, but you need to go home and get some sleep. How are you going to remember where you left off when you come back in the morning? COMMENTS Comments have two entirely different purposes within a T-SQL batch or stored procedure. First, they can be used to document code, to make it easier for folks who have to maintain software in the future. Second, they can be used to temporarily disable lines of code within your batch when you re trying to get it working.

For reliable and cheap web hosting services please check cheap web hosting website.

Comments are closed.