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”这个字段执行的时候根本就没用上 不知道哪错了
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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28