我有一个字段是文本型的,里面存的是日期,如:02-12-27。现在我想在edit中输入一个月份,如:02-12,(20分)

  • 主题发起人 人鱼公主:)
  • 开始时间

人鱼公主:)

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个字段是文本型的,里面存的是日期,如:02-12-27。现在我想在edit中输入一个月份,如:02-12,
并且查找出符合条件的记录,我应该怎么从字段日期中取出前几位呢
 
0-4
五位
 
不就是查询吗?你那种做法太麻烦了,用模糊查询就ok了。。。。
 
用>=02-12-01
<=02-12-31
要不然就取字符串长度
 
要实现动态的月份查询
 
你把输入的月份第一天的最后一天求出来查不就可以了
 
copy(日期,1,5)就可以了
 
with adoquery1 do
begin
close;
sql.clear;
SQL.Add('select * from cipher where Cus_Phone like ''%' + Edit_Phone.Text + '%''');
open;
end;
cus_phone字段是电话号码,edit_phone.text是查询值
例如:cus_phone=123456 那末无论edit_phone.text=123 ,1234,234,还是456都可查出来
这应该满足你的要求了
 
copy(日期,1,5)
具体应该怎么写这个语句呢
 
要看你的日期格式是yy-mm-dd还是yy-m-d
 
function Copy(S; Index, Count: Integer): string;

S为字符串
index为开始位置
count为要copy的长度

S := '2002-12-12'
S := Copy(S,1,7);
结果S为'2002-12'

 
adoquery1.SQL.text:=format('select * from kucun where 日期 like ''%s'' and 型号=''%s''',[edit1.text,edit2.text]);
为什么查不到呢
 
patriot的sql好像不满足要求,他要查出来的是02-12月的数据,如果你这样查询会
把02-02-12的数据查询出来的,我想应该是第一个%不要
StrUtils.pas
首部 function LeftStr(const AText: string; const ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText左边的ACount个字符
说明 LeftStr('123456', 3) = '123'
参考 function System.Copy
例子 Edit3.Text := LeftStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function RightStr(const AText: string; const ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText右边的ACount个字符
说明 RightStr('123456', 3) = '456'
参考 function System.Copy
例子 Edit3.Text := RightStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function MidStr(const AText: string; const AStart, ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText从AStart开始的ACount个字符
说明 其实就是Copy
参考 function System.Copy
例子 Edit3.Text := MidStr(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value);
 
我上面的语句错在哪里呢
 
adoquery1.sql.text:=format('select * from kucrn where 库存类型=''aaa'' and 型号=''%s'' and 日期 Like #%s%#,[edit1.text,edit3.text])
 
为什么查询不到呢
 
select * from cipher where Cus_Phone like ''' + Edit_Phone.Text + '___'''
___代表后边的三位,是按位数模糊匹配的
另外您的日期是yy-mm-dd么,这个必须保证,别存成02-1-1,那可坏了
 
日期是yy-mm-dd,那么我应该怎么写呢
 
select * from cipher where Cus_Phone like ''' + Edit_Phone.Text + '___'''
就这样写啊
一个下划线代表一位,我那是三位,不就是代表02-12后面的是任意日期了么
 
有时候可以查到,有时候查不到,还是不太稳定
 
顶部