I am looking through a stored procedure and seeing many lines like:
case when len(isnull(INVOICE.INVOICE_DATE,'')) > 0
and isdate(INVOICE.INVOICE_DATE) = 1
then convert(datetime,INVOICE.INVOICE_DATE)
else null end
and
case when len(isnull(SHIPMENT.NET_AMOUNT_DUE,'')) > 0
and isnumeric(SHIPMENT.NET_AMOUNT_DUE) = 1
then convert(money,SHIPMENT.NET_AMOUNT_DUE)
else null end
I don’t understand why the ISNULL and LEN checks are always there. Is there some benefit that I am missing? Conversely, is there any detriment to how the code is currently written?
The
LENandISNULLchecks are not needed.ISDATEandISNUMERICwill return a0if the value isNULLor empty, so this is just not needed. Possibly someone being extra extra cautious…These can be written as:
And: