SQL如何比较varchar字段中的数值?

来源:百度知道 编辑:UC知道 时间:2024/06/05 21:58:17
strSql = "select fl from mydb where fl>'0' and fl<'2'"

因字段中有小数位,结果中把
1.6
145.11
都列出来了,我只是要大于0,小于2的字段列出来,请问应如何做?

在查询里把fl字段转换成numeric类型,再比较就可以了。
strsql="select fl from mydb where cast(fl as numeric(18,2))>0 and cast(fl as numeric(18,2))<2"

为什么fl是varchar型,而不是int?
varchar类型是按照ACCSII从第一个开始比较,然后第二个。。。