关于sql语句的一个问题(30分)

  • 主题发起人 主题发起人 wencyu
  • 开始时间 开始时间
W

wencyu

Unregistered / Unconfirmed
GUEST, unregistred user!
在delphi中要进行一项查询制单号的工作,制单号是hy0001,hy0002---hy0006----hy1000,后四位是制单号的序号,要按序号查
询某一范围的制单号应该怎么写查询语句。我不会呀!
 
你用什么数据库?
 
for i := low to high do
begin
str = hy + inttostr(i); //这边要处理一下,以便补零
sqlstr = 'select * from tablename where id = ''' + str + '''';
end;
 
我认为他的意思是查询编号在再一个范围之内的记录,但是他的编号又含有字母,所以没
办法简单的写where语句,这时就要用到SubStr()函数,但是这个函数在不用的数据库中的
格式又不一样
 
用的是sqls server数据库
 
select * from table1 where id>'hy0001' and id <'hy0010'
不就行了?
 
Query.sql.text:=
'select * from tablename where substring(fieldname,3,4)>:star and substring(fieldname,3,4)<:end';
query.parambyname('Star').asstring := xxxxx'
Query.parambyname('end').asstring:= xxxx;
query.active:= true;
 
用Right()函數就可,因為其后四位為序號。
var start,end:string;
start:=?;//輸入
end:=?;//輸入
query.close;
query.sql.text:='select * from tablename where right(fieldname,4)>'''+start+''' and right(fieldname,4)<'''+end+'''';
query.prepare;
query.open;
 
select * from TAbleName
where Cast(substring(FieldName, 3, 10) As Int) > 10
and Cast(substring(FieldName, 3, 10) As Int) < 50
类似
 
你可以用between and 來查詢
例如
Select * From aa where 所在的字段名 between '' and ''
就可以了
 
后退
顶部