The Daily WTF
Clara had a database of users. The EmailAddress field in the user table was, by design, nullable, but some downstream applications didn’t like nulls and wanted something there. Now, it didn’t particularly matter what the values were, just that there were some, so Clara wrote up a quick stored procedure that would return the users with the null emails converted to the format BlankEmail_YYYYMMDD, e.g., BlankEmail_20230726.
This was all well and good until one of the senior developers decided that Clara’s use of the T-SQL date functions was killing performance. They made this decision based on being the senior developer, but not based on any metrics or performance monitoring. Real seniors don’t need such trivialities- they know what badly performing code is just by looking at it.
So that senior developer wrote this function, guaranteed to perform better.
CREATE FUNCTION [dbo].[fnGetDate_Formatted] (@Datetime DATETIME, @FormatMask VARCHAR(32)) RETURNS VARCHAR(32) AS BEGIN DECLARE
To read the full article click on the 'post' link at the top.