there's not really a good way and, frankly, you shouldn't. TSQL is a great language for querying databases and manipulating data. It's quite horrible at all other tasks. I'd suggest raising an error and then letting whatever is calling the query handle the logging.