17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix A: System Functions<br />

NULLIF<br />

The NULLIF function compares two expressions and returns a NULL value. The syntax is as follows:<br />

NULLIF(, )<br />

PARSENAME<br />

The PARSENAME function returns the specified part of an object name. The syntax is as follows:<br />

PARSENAME(‘’, )<br />

The object_name parameter specifies the object name from the part that is to be retrieved. The<br />

object_piece parameter specifies the part of the object to return. The object_piece parameter takes<br />

one of these possible values:<br />

❑ 1 — Object name<br />

❑ 2 — Owner name<br />

❑ 3 — Database name<br />

❑ 4 — <strong>Server</strong> name<br />

PERMISSIONS<br />

The PERMISSIONS function returns a value containing a bitmap, which indicates the statement, object, or<br />

column permissions for the current user. The syntax is as follows:<br />

PERMISSIONS([ [, ‘’]])<br />

The object_id parameter specifies the ID of an object. The optional column parameter specifies the<br />

name of the column for which permission information is being returned.<br />

@@ROWCOUNT<br />

Returns the number of rows affected by the last statement.<br />

One of the most used globals, my most common use for this one is to check for non–run-time errors — that<br />

is, items that are logically errors to your program but that <strong>SQL</strong> <strong>Server</strong> isn’t going to see any problem with.<br />

An example is a situation where you are performing an update based on a condition, but you find that it<br />

affects zero rows. Odds are that, if your client submitted a modification for a particular row, then it was<br />

expecting that row to match the criteria given — zero rows affected is indicative of something being wrong.<br />

However, if you test this system function on any statement that does not return rows, then you will also<br />

return a value of 0.<br />

ROWCOUNT_BIG<br />

644<br />

The ROWCOUNT_BIG function is very similar to @@ROWCOUNT in that it returns the number of rows from<br />

the last statement. However, the value returned is of a data type of bigint. The syntax is as follows:<br />

ROWCOUNT_BIG()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!