Sometimes you are looking for an easier solution then you are used to. Today i had one in that category. Nothing new, but simple and effective. But while writing this post i came up something quite cool which can answer almost any question i had in SQL Server coding best practices. They are called TRACE FLAGS. An Undocumented feature of SQL Server. You can read all about them in a very good post from Benjamin Nevarez, called “http://www.benjaminnevarez.com/2012/04/more-undocumented-query-optimizer-trace-flags/“. Anyways, i used the 8605 traceflag on my examples below, and i came to a very strange result. I was trying to tell that using a COALESCE function to generated a semi-column separated list would be better then to use the old string concatenation way. But then….
The COALESCE function.
An easy solution to get rid off null values, but also to create separated lists is the COALESCE