The thing I hate the most about these two functions is that you need to know the right magic spells to make them work. Let’s look at
SERVERPROPERTY()first. The syntax for the function is
SERVERPROPERTY( 'propertyname' ), which is easy enough syntax, but the list of values for
propertynameisn’t discoverable from SQL Server metadata, DMVs, or even IntelliSense. Instead, I need to check the docs for the list of allowable values. These property names are essentially magic words, and I need to check my spell book to make sure I get it right.
Invalid values for
NULL–which is easy enough to handle, but also means your code will compile and run, but might do unintended things if you get your magic spell wrong, due to a typo.
Click through for Andy’s solution to the problem.