--先拆分再比较 if object_id('tb') is not null drop table tb go create table tb ( col1 varchar(10) ) insert into tb select '30' union all select '200' union all select '2' union all select '400-500' union all select '500' union all select 'AAA' go select distinct(col1) from tb a cross join master..spt_values b where type='p' and number between 1 and len(col1) and substring('-'+col1,number,1)='-' and isnumeric(substring(col1,number,charindex('-',col1+'-',number)-number))=1 and substring(col1,number,charindex('-',col1+'-',number)-number)>300 /* col1 ---------- 400-500 500(2 行受影响) */
这个问题没说清楚,我来说明下。 Access数据库,asp程序,数据表tt中的字段a,a是文本类型。存储的数据30 200 1000 2 400-500 10 500 AAA 面议现在想按条件查询tt表中字段a的值的数据。 sele * from tt where val(列名)<300 这条语句可以实现查询。但比较条件是一个数值(300),我想吧300换成一个变量f(f=300),并且f已经转换成int类型,但查询结果仍不对,1000也在查询结果中。 求解。 (简单的说就是,文本字段按数值查询)
declare f int set f=300 sele * from tt where val(列名)<f行不?
--先拆分再比较
if object_id('tb') is not null
drop table tb
go
create table tb
(
col1 varchar(10)
)
insert into tb
select '30' union all
select '200' union all
select '2' union all
select '400-500' union all
select '500' union all
select 'AAA'
go
select distinct(col1) from tb a cross join master..spt_values b where type='p' and number between 1 and len(col1) and substring('-'+col1,number,1)='-' and isnumeric(substring(col1,number,charindex('-',col1+'-',number)-number))=1 and substring(col1,number,charindex('-',col1+'-',number)-number)>300
/*
col1
----------
400-500
500(2 行受影响)
*/
Access数据库,asp程序,数据表tt中的字段a,a是文本类型。存储的数据30
200
1000
2
400-500
10
500
AAA
面议现在想按条件查询tt表中字段a的值的数据。
sele * from tt where val(列名)<300 这条语句可以实现查询。但比较条件是一个数值(300),我想吧300换成一个变量f(f=300),并且f已经转换成int类型,但查询结果仍不对,1000也在查询结果中。
求解。
(简单的说就是,文本字段按数值查询)
set f=300
sele * from tt where val(列名)<f行不?
第一句提示语句未结束,ASP可以这样写吗。
这是SQL语法