数据库中的字段是varbinary类型的,而且转换以后不一定是数字
我给出一个数字(float),要取出跟他最接近的(大于、小于、或等于都有可能)
我感觉转换类型比较的时候很复杂,郁闷了一天半了~~
请各位高手指点下,谢谢~~
---------------------------------------------------------------
declare @数字 float
set @数字=100 --要查询的数字
select top 1 * from 表
where isnumeric(字段)=1
order by abs(cast(cast(字段 as varchar) as float)-@数字)
---------------------------------------------------------------
select top 1 * from 表
where isnumber(convert(varchar(1000),字段))=1
and convert(float,convert(varchar(1000),字段)))>=某个值
order by convert(float,convert(varchar(1000),字段)))
select top 1 * from 表
where isnumber(convert(varchar(1000),字段))=1
and convert(float,convert(varchar(1000),字段)))<=某个值
order by convert(float,convert(varchar(1000),字段))) desc