+ -
当前位置:首页 → 问答吧 → Delphi 查询语句代码问题 求解决

Delphi 查询语句代码问题 求解决

时间:2011-08-18

来源:互联网

begin

  sql1 := 'select isnull(a.ks_name,b.ks_name) as q,isnull(a.TotalZhichu,0) as w,isnull(b.TotalShouru,0) as e from ';
  sql1 :=sql1+'(select ks_name,sum(zhichujine) as TotalZhichu from yz_qyzc where 1>0' +s1+ 'group by ks_name) a full join(select ks_name,sum(fyje) as TotalShouru from yz_qysr where 1>0 '+s1+' group by ks_name) b on a.ks_name=b.ks_name where 1>0 ';

  if (ComboBox1.Text <> '') and (ComboBox1.Text <> '全院科室') then
  begin
  sql1 := sql1+ ' and a.ks_name='+''''+trim(ComboBox1.Text)+'''';
  end;
  if RadioButton1.Checked = true then
  begin
  s1 := 'and fydate>= '+''''+datetostr(DateTimePicker1.Date)+'''' + 'and fydate<= '+''''+datetostr(DateTimePicker2.Date)+'''';
  end;
  if RadioButton4.Checked = true then
  begin
  if ComboBox10.Text <> '' then
  begin

  s1 := ' and fydate like '+ ''''+'%'+trim(ComboBox10.Text)+'%'+'''';
  end;

  end;
  if RadioButton2.Checked = true then
  begin
  if (ComboBox4.Text <> '')and (ComboBox5.Text <> '')and(ComboBox6.Text <> '')and(ComboBox7.Text <> '')then
  begin
  MyDate1 := EncodeDate(StrToInt(ComboBox4.Text), StrToInt(ComboBox5.Text), 1);


  if ComboBox7.Text <> '12' then
  begin
  MyDate2 := EncodeDate(StrToInt(ComboBox6.Text), (StrToInt(ComboBox7.Text)+1), 1)

  end else
  begin
  MyDate2 := EncodeDate(StrToInt(ComboBox6.Text), 12, 31);
  end;
  if MyDate1 <= MyDate2 then
  begin
  time1 := DateToStr(MyDate1);
  time2 := DateToStr(MyDate2);
  s1 := ' and fydate>= '+''''+time1 +'''' + 'and fydate<= '+''''+time2+'''' ;
  end
  else begin
  MessageBox(Handle, PChar('查询日期范围不正确!'), PChar('提示'), MB_OK);
  exit;
  ComboBox4.SetFocus;
  end;

  end;
  end;
  不好意思 代码有点长 我就是想加个按时间查询 但是“s1”这个字段执行的时候根本就没用上 不知道哪错了

作者: youling446   发布时间: 2011-08-18

热门下载

更多