sql大于语句返回小于和大于的值

时间:2017-03-07 17:57:46

标签: sql sql-server

我知道我的问题是该值是一个字符串,但我该如何解决它并返回正确的结果?

这是我的查询和返回结果的摘录

select [Count of Disk Errors], _ResourceGuid  from Inv_Hard_Disk_Errors
where _resourceguid in (select guid from vComputer where IsManaged = '1')
and [COUNT of Disk Errors] > '250'
order by 1 desc

Count of Disk Errors    _ResourceGuid
99                     DDDC8FDE-46CD-493F-8AB9-0570DECE9183
9                      005E111E-B04B-44C8-B6FE-37FBC9547B8D
88                     E6BB97E7-67AE-4DF5-BD44-C1612098B137
87                     A0EE300B-C449-4E3A-9B82-7442F3AEDF11
8                      9A73D013-D2BA-43DC-A213-EF8FC9789498

1 个答案:

答案 0 :(得分:2)

select [Count of Disk Errors], _ResourceGuid  
from Inv_Hard_Disk_Errors
where _resourceguid in (select guid from vComputer where IsManaged = '1')
  and try_cast([COUNT of Disk Errors] as int) > 250
order by try_cast([COUNT of Disk Errors] as int) desc

在Sql Server 2012及更高版本中:当转换失败而不是错误时,每个都会返回null