Avoid function execution when parameters are null

There is a specific syntax TSQL provides for skipping function execution when any parameters are NULL.  This often cleans-up code that would otherwise have to use branching logic to avoid the execution.  Fast, simple, and handy.

   @MyParm1    nvarchar(max)
  ,@MyParm2    datetimeoffset
) returns bit
with returns null on null input

(Available on SQL 2005 and later)


About tim.edlund

Tim Edlund founded Softworks Group Inc. in 1990. As CEO, Tim is responsible for setting strategy and leading product R&D. Tim has maintained expertise in database technologies and is an Agile methodology evangelist. He also enjoys staying fit , skiing and trying to survive parenting teenagers.
Link | This entry was posted in SQL Sever & TSQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s