请问一下关于很简单的查询问题? (5分)

  • 主题发起人 主题发起人 hnzcg124
  • 开始时间 开始时间
H

hnzcg124

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
procedure Tsb_rcxhjcgl.N2Click(Sender: TObject);
var sb,da1,da2:string;
begin
case dayofweek(date) of
1: begin
sb:='1899-12-24';
da1:=datetimetostr(date+strtodatetime(sb));
clientdataset1.Close;
clientdataset1.CommandText:='select * from sb_rcxhjcgl where xjsj>='+''''+da1+'''';
clientdataset1.Open;//sunday
end;
2: begin
sb:='1899-12-30';
da2:=datetimetostr(date+strtodatetime(sb));
clientdataset1.Close;
clientdataset1.CommandText:='select * from sb_rcxhjcgl where xjsj>='+''''+da2+'''';
clientdataset1.Open;
end;//monday
3: begin
sb:='1899-12-29';
da:=datetimetostr(date+strtodatetime(sb));
clientdataset1.Close;
clientdataset1.CommandText:='select * from sb_rcxhjcgl where xjsj>='+''''+da+'''';';
clientdataset1.Open;//tuesday
end;
4: begin
sb:='1899-12-28';
da:=datetimetostr(date+strtodatetime(sb));
clientdataset1.Close

clientdataset1.CommandText:='select * from sb_rcxhjcgl where xjsj>='+''''+da+'''';';
clientdataset1.Open;//wednesday
end;
5: begin
sb:='1899-12-27';
da:=datetimetostr(date+strtodatetime(sb));
clientdataset1.Close;
clientdataset1.CommandText:='select * from sb_rcxhjcgl where xjsj>='+''''+da+'''';';
clientdataset1.Open;
end;//thursday
6: begin
sb:='1899-12-26';
da:=datetimetostr(date+strtodatetime(sb));
clientdataset1.Close;
clientdataset1.CommandText:='select * from sb_rcxhjcglwhere xjsj>='+''''+da+'''';';
clientdataset1.Open

end;//friday
7: begin
sb:='1899-12-25';
da2:=datetimetostr(date+strtodatetime(sb));
clientdataset1.Close;
clientdataset1.CommandText:='select * from sb_rcxhjcgl where xjsj>='+''''+da+'''';';
clientdataset1.Open;
end;//statusday
end;
end;//以上为根据本周记录,提取系统时间得出星期几来查找

这是原来公司老员工做周查询,我觉得应该有更简单的方法,怎么实现呢?还有他这里面查询看不懂,按说1 23等只是对应的是一天的呀?????
 
procedure Tsb_rcxhjcgl.N2Click(Sender: TObject);
var
t: TDateTime

sb,da1,da2:string;
begin
t := DayOfWeek(Date) - 2;
if t < 0 then Inc(t, 7);
clientdataset1.Close;
clientdataset1.CommandText:='select * from sb_rcxhjcgl where xjsj>='+''''+datetimetostr(date - t) + '''';
clientdataset1.Open;//sunday
end;//以上为根据本周记录,提取系统时间得出星期几来查找
 
DayOfWeek(Date) - 2什么意思?
 
你好象没有仔细看原来的那段程序啊。
程序的含义是:查找在今天前面的那个周一开始的所有记录。如果今天是周一,那就只查今天的,如果是周二,那就从昨天开始……
而周一的时候,DayOfWeek() = 2,所以,就要这样了。
 
多人接受答案了。
 
后退
顶部