Sql 使用最小算术溢出时,将表达式转换为数据类型datetime时出错
我的以下查询抛出了一个错误,我不太明白为什么:Sql 使用最小算术溢出时,将表达式转换为数据类型datetime时出错,sql,sql-server,datetime,Sql,Sql Server,Datetime,我的以下查询抛出了一个错误,我不太明白为什么: Select * from Correspondences where case_id in(000021,00000991,000081,0000731) and case_id in(Select min(comm_date_utc) from Correspondences where case_id in (000021,00000991,000081,0000731)) S
Select * from Correspondences
where case_id in(000021,00000991,000081,0000731)
and case_id in(Select min(comm_date_utc) from Correspondences where case_id in (000021,00000991,000081,0000731))
SQL server给了我以下错误:
Msg 8115,16级,状态2,第1行
将表达式转换为数据类型datetime时出现算术溢出错误
有谁能帮我理解我为什么要这样做?我想这就是你想要的:
Select c.*
from Correspondences c
where case_id in(000021,00000991,000081,0000731)
and comm_date_utc = (Select min(comm_date_utc)
from Correspondences c2
where c2.case_id = c.case_id
);
查询的问题在于它将
caseid
与datetime之类的东西进行比较。此查询根据时间返回每个案例的第一条记录。后者似乎更像是查询的目的。为什么要将caseid
(显然是整数或类似整数的字符串)与日期进行比较?