运行case语句时转换失败错误

问题描述 投票:0回答:1

我运行以下case语句时收到错误消息'将varchar值'NO'转换为数据类型int时转换失败。有人可以告诉我我在做什么错吗?谢谢

,CASE
         WHEN DATEDIFF(DAY, convert(VARCHAR, Deliveries.DUE_DATE, 10), convert(VARCHAR, DELIVERIES.OB_DELIVERY_DATE, 10)) > 0
                THEN DATEDIFF(DAY, convert(VARCHAR, Deliveries.DUE_DATE, 10), convert(VARCHAR, DELIVERIES.OB_DELIVERY_DATE, 10))
         WHEN DATEDIFF(DAY, convert(VARCHAR, Deliveries.DUE_DATE, 10), convert(VARCHAR, DELIVERIES.OB_DELIVERY_DATE, 10)) < 0
                THEN DATEDIFF(DAY, convert(VARCHAR, Deliveries.DUE_DATE, 10), convert(VARCHAR, DELIVERIES.OB_DELIVERY_DATE, 10))

          ELSE 'NO'

       END AS DAYS_BEFORE_DUE_DATE
sql tsql varchar
1个回答
0
投票

case语句中,只能返回一种数据类型。但是,您可以使用NULL代替NO

© www.soinside.com 2019 - 2024. All rights reserved.