SQL Server 算术溢出错误将表达式转换为数据类型日期时间 [英] SQL Server Arithmetic overflow error converting expression to data type datetime

查看:35
本文介绍了SQL Server 算术溢出错误将表达式转换为数据类型日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义我的订单,如果数量为负,那么该行必须排在第一位,如果数量为正,我将按 ExpDate 对其进行排序

I want to customize my order by , if the Qty is negative then that row must be in fist then if the Qty is positive I will sort it by ExpDate

SELECT WhsCode,
       ItemCode,
       LotNumber,
       ExpDate,
       Qty
FROM rq_Test2
ORDER BY CASE
             WHEN qty < 0 THEN Qty
             ELSE ExpDate
         END

但是我收到了将表达式转换为数据类型日期时间的算术溢出错误."的错误.为什么?

But I am getting an error of " Arithmetic overflow error converting expression to data type datetime. " .. Why ?

谢谢..

推荐答案

有两个 case 语句

Have two case statements

Select 
      WhsCode,
      ItemCode,
      LotNumber,
      ExpDate,
      Qty 
from rq_Test2 
order by case when qty < 0 then Qty else null end ,
         case when qty > 0 then ExpDate else NULL end

这篇关于SQL Server 算术溢出错误将表达式转换为数据类型日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆