1

我正在查看存储过程并看到许多行,例如:

case when len(isnull(INVOICE.INVOICE_DATE,'')) > 0 
      and isdate(INVOICE.INVOICE_DATE) = 1 
    then convert(datetime,INVOICE.INVOICE_DATE)
    else null end

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

我不明白为什么ISNULLLEN检查总是在那里。我缺少一些好处吗?相反,代码当前的编写方式是否有任何损害?

4

1 回答 1

6

LEN不需要和检查ISNULL

ISDATE如果值为或为空,ISNUMERIC将返回 a ,所以这不是必需的。可能有人特别小心...0NULL

这些可以写成:

case when ISDATE(INVOICE.INVOICE_DATE) = 1 
    then convert(datetime,INVOICE.INVOICE_DATE)
    else null end

和:

case when ISNUMERIC(SHIPMENT.NET_AMOUNT_DUE) = 1
   then convert(money,SHIPMENT.NET_AMOUNT_DUE) 
   else null end
于 2012-05-14T15:14:11.217 回答