请教:关于SQL查询问题(100分)

  • 主题发起人 主题发起人 qingang888
  • 开始时间 开始时间
Q

qingang888

Unregistered / Unconfirmed
GUEST, unregistred user!
某表的一字符型字段的值为:
1-1-1
1-1-2
。。。
。。。
1-1-50
。。。
。。。
1-1-100
如何用SQL实现查询显示该字段值在1-1-1到1-1-50间的记录
百思不得其解,特向各位大侠请教。
 
select * from tbl where fieldname between '1-1-1' and '1-1-50'
 
select * from 表名 where a1>'1-1-1' and a1<'1-1-50'
好象可以
 
select * from tablename where convert(int, substring(a1,5,5)) between 1 and 50
 
楼上的说的都是对的
不过wangnen和mlzhou的方法简单些
pearl.搞得复杂了
 
是吗?
请问1-1-6的记录wangnen和mlzhou的方法哪位能取出来?
 
我的错了。
但是建议qingang888最好象这样的数据最好写成这样的形式1-1-001
 
to Pearl
你是正确的,我们错了
 
同意
Pearl的
 
是啊,用substring截字符串,再转换类型就行了,
不过不同的数据库要用不同的函数
 
按pearl所说,我的语句更改后如下:(设备槽路是表名,系统源槽路是字段名)
QuerySBCL.SQL.Add('select *');
QuerySBCL.SQL.Add('from 设备槽路');
QuerySBCL.SQL.Add('Where convert(int,substring(系统源槽路,5,5)) between 1 to 50 ');

但运行出现“invalid use of keyword”错误
怎么回事?
 
QuerySBCL.SQL.Add('Where convert(int,substring(系统源槽路,5,5)) between 1 AND 50 ');
 
Hehe ~~~
between...and
I make a mistake yestoday:write Values as "Valuse", hehe ~~~~~
 
SORRY,打错了,是:
QuerySBCL.SQL.Add('Where convert(int,substring(系统源槽路,5,5)) between 1 AND 50 ');
但运行出现“invalid use of keyword”错误???
 
有谁知道是怎么回事吗????
 
你的是什么数据库?
你直接在数据库端运行这些语句试试?
sql server2000应该没问题的啊!!
如果还不行,用cast转换类型试试,substring应该没有问题!
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
930
SUNSTONE的Delphi笔记
S
D
回复
0
查看
936
DelphiTeacher的专栏
D
D
回复
0
查看
730
DelphiTeacher的专栏
D
D
回复
0
查看
690
DelphiTeacher的专栏
D
后退
顶部