• Zososql - Friday, January 20, 2017 4:06 PM

    datediff(dd,CASE stats.abbrev WHEN 'A' THEN CONVERT(VARCHAR, eventscheduled, 111) END, CASE stats.abbrev WHEN 'B' THEN CONVERT(VARCHAR, eventscheduled, 111) END)

    The above function will always return NULL.  When stat.abbrev = 'A', then stats.abbrev cannot = 'B', so the second CASE expression will return the (unspecified) default value of NULL.  When stats.abbrev = 'B' then stats.abbrev cannot = 'A', so the first CASE expression will return the (unspecified) default value of NULL.  (Both will return NULL when stats.abbrev is neither 'A' nor 'B'.)

    When troubleshooting complex expressions like this, you should always take them apart to make sure that you are getting the values that you expect for subcomponents of those expressions.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA