pb 动态改变DW的WHERE子句
PB心得4-动态改变DW的WHERE子句
在DW的FILTER的使用一文中提到如果检索条件因素不固定的话,可以使用动态改变DW的WHERE子句的方法。
这个方法的实现是这样的,做一个没有参数的DW,在程序中,先通过DW.OBJECT.DATAWINDOW.TABLE.SELECT来取得DW对象的SQL语法,可以对SQL语法拆分出SELECT部分,WHRER部分,GROUP BY部分,HAVING部分。如果是UNION ALL 那么应该需要用数组变量来接收对应的部分,这些变量最好是用环境变量。
再做个用于查询条件的DW,里面是你可以让用户输入查询条件的字段项目。然后在查询按钮的脚本下做如下面的步骤,读取查询条件的字段对应的条件值,对每个条件值做判断,如果是不为空的才需要生成对应的条件语法,根据字段的不同,合成条件语法时注意引号和类型转换。条件之间的逻辑,运算优先级等。
合成后的整个新的条件语法与原来的SQL语法的WHRER部分合并,再与其他的SQL的部分合并成完整的新的条件的SQL语法。
把新的SQL语法通过DW.OBJECT.DATAWINDOW.TABLE.SELECT传回给DW,并运行检索函数。
string ls_odd
string ls_provider
string ls_receiver
string ls_oddtype
datetime ldt_start,ldt_end
string ls_stockcode
string ls_stockname
string ls_sql
string ls_where,ls_where1
string ls_type1
string ls_type2
string ls_cid
datawindowchild ldwc_1
dw_inquire.accepttext()
string ls_sql1
ls_sql = mid(is_sql,1,pos(is_sql,'union all') - 1)
ls_sql1 = mid(is_sql,pos(is_sql,'union all') + 9,len(is_sql) - pos(is_sql,'union all') +1)
ls_odd = dw_inquire.object.oddno[1]
ls_provider = dw_inquire.object.provider[1]
ls_receiver = dw_inquire.object.receiver[1]
ls_oddtype = dw_inquire.object.oddtype[1]
ls_stockcode = dw_inquire.object.stockcode[1]
ls_stockname = dw_inquire.object.stockname[1]
ldt_start = dw_inquire.object.dstart[1]
ldt_end = dw_inquire.object.dend[1]
ls_type1 = dw_inquire.object.type1[1]
ls_type2 = dw_inquire.object.type2[1]
ls_cid = dw_inquire.object.cid[1]
if pos(lower(is_sql),'where')>0 then
ls_where = ' '
ls_where += " and out_main.auditing = '"+ls_type2+"' "
else
ls_where = ' where '
ls_where += " out_main.auditing = '"+ls_type2+"' "
end if
if pos(lower(ls_sql1),'where')>0 then
ls_where1 = ' '
ls_where1 += " and group_out.auditing = '"+ls_type2+"' "
else
ls_where1 = ' where '
ls_where1 += " group_out.auditing = '"+ls_type2+"' "
end if
if not(isnull(ls_odd) or len(trim(ls_odd)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.odd_no like '%" + ls_odd + "%' "
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " group_out.odd_no like '%" + ls_odd + "%' "
end if
if not(isnull(ls_provider) or len(trim(ls_provider)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.provider = '" + ls_provider + "' "
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " group_out.provider = '" + ls_provider + "' "
end if
if not(isnull(ls_receiver) or len(trim(ls_receiver)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.receiver= '" + ls_receiver + "' "
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " group_out.receiver = '" + ls_receiver + "' "
end if
if not(isnull(ls_oddtype) or len(trim(ls_oddtype)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.receiver_provider_type= '" + ls_oddtype + "' "
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " group_out.receiver_provider_type= '" + ls_oddtype + "' "
end if
if not(isnull(ls_stockcode) or len(trim(ls_stockcode)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
//if len(ls_stockcode) = 5 then
ls_where += " out_child.pid = " + ls_stockcode + " "
// else
// ls_where += " out_child.stock_code like '" + ls_stockcode + "%' "
//end if
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " 1 = 2 "
end if
if not(isnull(ls_stockname) or len(trim(ls_stockname)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_child.stock_name like '%" + ls_stockname + "%' "
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " 1=2 "
end if
if not(isnull(ls_cid) or len(trim(ls_cid)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_child.cid = " + ls_cid + " "
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " 1=2 "
end if
if ls_type2 = '1' then
if not(isnull(ldt_start)) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.auditdate >= '" + string(ldt_start,'yyyy-mm-dd') +" 00:00:00' "
end if
if not(isnull(ldt_end)) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.auditdate <= '" + string(ldt_end,'yyyy-mm-dd') +" 23:59:59' "
end if
else
if not(isnull(ldt_start)) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.odd_date >= '" + string(ldt_start,'yyyy-mm-dd') +" 00:00:00' "
end if
if not(isnull(ldt_end)) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.odd_date <= '" + string(ldt_end,'yyyy-mm-dd') +" 23:59:59' "
end if
end if
if not(isnull(ldt_start)) then
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " group_out.odd_date >= '" + string(ldt_start,'yyyy-mm-dd') +" 00:00:00' "
end if
if not(isnull(ldt_end)) then
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " group_out.odd_date <= '" + string(ldt_end,'yyyy-mm-dd') +" 23:59:59' "
end if
if not(isnull(ls_type1) or len(trim(ls_type1)) = 0) then
if len(ls_where) > 5 then ls_where += ' and '
ls_where += " out_main.relate_no like '%" + ls_type1 + "%' "
if len(ls_where1) > 5 then ls_where1 += ' and '
ls_where1 += " 1=2 "
end if
//messagebox('',is_sql + ls_where)
dw_print.object.datawindow.table.select = ls_sql + ls_where + ' union all ' + ls_sql1 + ls_where1
dw_print.settransobject(sqlca)
dw_print.retrieve()
这种方法最好就是在合成后检查一下合成的语法是否正确,要考虑原SQL语法是否有WHERE条件,如果没有新合成的要加上WHERE关键字。
=========================实践
SQL:
select bill_id,bill_date,org_id,b.memb_id,memb_nm,decode(sex,'M','男','F','女',sex) sex,bill_money,cash_money,card_money,accm_money,coupon_money from
(select bill_id,bill_date,org_id,memb_id,bill_money,cash_money,card_money,accm_money,coupon_money from TB_AX006 t)s,
(select memb_id,memb_nm,sex from tb_ax001 a) b
where s.memb_id = b.memb_id(+)
PB:
String ls_value,ls_sql,ls_where
String ls_dt_str,ls_dt_end
String ls_ddlb_1,ls_sle_1
string ls_ddlb_2
ls_sql=dw_1.OBJECT.DATAWINDOW.TABLE.SELECT
//messagebox("提示",ls_sql)
if pos(lower(ls_sql),'+')>0 then
ls_sql=mid(ls_sql,1,pos(ls_sql,'+') + 1)
//messagebox("截取后sql",ls_sql)
end if
//时间
ls_dt_str = string(dp_1.value,'yyyy/mm/dd')
ls_dt_end = string(dp_2.value,'yyyy/mm/dd')
if dp_1.value > dp_2.value then
messagebox("提示","开始时间不能小于结束时间")
return
end if
ls_where += " and s.bill_date between to_date('"+ls_dt_str+"','yyyy-mm-dd') and to_date('"+ls_dt_end+"','yyyy-mm-dd') "
//会员
ls_ddlb_1 = trim(ddlb_1.text)
ls_sle_1 = upper(trim(sle_1.text))
IF ls_ddlb_1 = '会员姓名' THEN
if ls_sle_1 = '' then
messagebox("提示","请输入会员姓名")
return
else
ls_where += " and upper(b.memb_nm) like '%"+ls_sle_1+"%' "
end if
ELSEIF ls_ddlb_1 = '会员ID' THEN
IF ls_sle_1 = '' THEN
MessageBox("确认", "请输会员ID.")
Return
elseif IsNumber(ls_sle_1) = false then
MessageBox("确认", "输入的不是数字.")
Return
else
ls_where +=" and b.memb_id = '"+ls_sle_1+"' "
END IF
END IF
//门店
ls_ddlb_2 = trim(ddlb_2.text)
if ls_ddlb_2 = '全部' then
ls_where += ""
else
ls_where += " and s.org_id ='"+ls_ddlb_2+"'"
end if
//messagebox('查询sql',ls_sql + ls_where)
dw_1.object.datawindow.table.select = ls_sql + ls_where
dw_1.settransobject(sqlca)
dw_1.retrieve()
转载于:https://www.cnblogs.com/jason-qi/p/4244357.html
pb 动态改变DW的WHERE子句相关推荐
- C# 设计时动态改变实体在PropertyGrid中显示出来的属性
方法一: /// <summary>/// 实体属性处理/// </summary>public class PropertyHandle{#region 反射控制只读.可见属 ...
- 使用CAShapeLayer实现一个音量大小动态改变的控件
一.案例演示 对于实时显示语音音量大小的需求,发现很多人的实现方式通过预放置多张图进行切换进行完成的.这样的处理,不但会浪费App的资源存储空间,而且效率也不高.对于符合某一定规律动态改变的图形,我们 ...
- uniapp、vue,vuex中state改变,getters不动态改变的完美解决方案!
uniapp.vue,vuex中state改变,getters不动态改变的完美解决方案! 参考文章: (1)uniapp.vue,vuex中state改变,getters不动态改变的完美解决方案! ( ...
- 解决javascript动态改变img的src属性图片不显示问题
解决javascript动态改变img的src属性图片不显示问题 参考文章: (1)解决javascript动态改变img的src属性图片不显示问题 (2)https://www.cnblogs.co ...
- 【Android 进程保活】oom_adj 值 ( oom_adj 值对应的进程优先级 | oom_adj 值动态改变 | 进程保活优化方向 )
文章目录 一.oom_adj 值对应的进程优先级 二.oom_adj 值动态改变 1.正常运行时的 oom_adj 值 2.按下 Home 键后的 oom_adj 值 3.按下回退键后的 oom_ad ...
- WEUI picker组件无法js动态改变选项
功能需求 设备号和摄像头都可以下拉选择,但是具体的摄像头下拉选项是根据设备号而定的.如下图,尾号为352的设备号只有前置摄像头,尾号为657的设备号前置和后置摄像头都有. 问题说明 一般情况下,这个需 ...
- js动态改变下拉菜单内容示例 .
<HTML><HEAD><TITLE>动态改变下拉菜单内容示例</TITLE></HEAD><SCRIPT LANGUAGE=java ...
- 动态改变select 宽度
有一个简单的办法:动态改变宽度 <select οnblur="this.style.width=30" οnfοcus="this.sty ...
- 如何动态改变框架的大小[转]
如何动态改变框架的大小 解决思路: 在框架所加载页中用parent.frames["框架名"].cols="值1,值2..." 或者parent.frames[ ...
最新文章
- Ubuntu 17.04 Chrome 安装
- java中的controller_详解Spring Boot中Controller用法
- Metasploit 之生成木马(msfvenom)
- c oracle 记录,ORACLE 19c 操作相关记录
- 2018百度之星程序设计大赛 - 资格赛 1002 子串查询
- Python多进程(process)和多线程(thread)的区别
- cisco 模拟器安装及交换机的基本配置实验心得_看完这份1113页的TCP/IP协议+路由与交换机,成功上岸字节跳动...
- 微信棋牌程序搭建Redis持久化存储(AOF与RDB两种模式)
- 脉冲耦合神经网络(PCNN)的python实现
- 计算机打不开硬盘,硬盘打不开的原因和解决方法
- 最新最全张家界旅游攻略(您必须知道的张家界攻略)
- 在2016年,Linux是否还需要Windows的支持呢
- 37手游基于云平台的大数据建设实践
- 微信小程序开发实战(12):滑杆组件(slider)和form组件
- 哔哩哔哩2018校招前端笔试
- hdu1827 1269 2767 强连通分支 刷水
- 贝壳找房 9月7日 笔试题 第四题-查族谱
- python程序填空_python练习题-基础巩固-第一周
- pragma warning
- cs6 mac 破解方法
热门文章
- Spark List组件滚动条加事件使datalist数据发生变化
- MySQL数据库基础(五)——SQL查询
- UIT创新科存储系统服务“500强”汽车名企
- nginx安装及负载均衡配置
- Some projects cannot be imported because they already exist in the workspace
- jquery 入门与知识
- 基于嵌入式webserver的服务器状态监控
- Android 控件之RatingBar评分条
- 一个漫长的程序人生路程,如何突破5000元大关?几年前的2-3线城市的参考,现在未必...
- java中自定义表单和流程_让驰骋工作流程引擎 ccbpm使用自定义表单来实现自己的业务逻辑....