SQL数据查询问题!

来源:百度知道 编辑:UC知道 时间:2024/05/08 09:48:04
数据库中有“收款单”表,表中有“账龄”字段,“账龄”字段是VARCHAR类型的。现在我想查询在某个时间段的数据(例如10-20天)。请问SQL的查询语句应该怎么写啊?
select cast('账龄' as int)as 账龄数 from 收款单 where 帐龄数 >'" + Val(Trim(Text5.Text)) + "' and 账龄数< '" + Val(Trim(Text9.Text)) + "' 。
我按照上面写的说是类型不匹配。
已经解决了。是后面的符合错误。。变量值是数字用双引号,字符用单引号

试试看这样子:

select cast([账龄] as int)as 账龄数 from 收款单 where 帐龄数 >'" + Val(Trim(Text5.Text)) + "' and 账龄数< '" + Val(Trim(Text9.Text)) + "' "

试试这个吧
select 账龄 from 收款单 where convert(int,账龄数)>'' + Val(Trim(Text5.Text)) + '' and convert(int,账龄数)< '' + Val(Trim(Text9.Text)) + ''