简单的查询问题求教!

InsideBlue 2002-05-14 10:40:38
请问如何把下面的查询改成支持模糊查询?

// 过滤查询
long ll_rowcount
long ll_row
long ll_j
string ls_filter_condition
0Astring ls_column
string ls_compare
string ls_value
string ls_and_or
string ls_column_type


if dw_query_condition.AcceptText() = -1 then return

ll_rowcount = dw_query_condition.rowcount()
if ll_rowcount <=0 then return


ls_filter_condition = ''

for ll_row = 1 to ll_rowcount

ls_column = dw_query_condition.getitemstring(ll_row, 'column_name')
0Als_compare = dw_query_condition.getitemstring(ll_row, 'compare')
ls_value = dw_query_condition.getitemstring(ll_row, 'value')
ls_and_or = dw_query_condition.getitemstring(ll_row, 'and_or')
ls_column_type = dw_query.Describe(ls_column 2B ".ColType")
ls_column_type = left(ls_column_type, 3)

if ll_row = ll_rowcount then //最后一行(不加and、or)

choose case ls_column_type //根据数据类型设置Filter条件
case 'cha' ,'var' ,'str'
if ls_compare="==" then
ls_filter_condition = ls_filter_condition + &
"Pos(" 2B ls_column + " , '" + ls_value +"')<>0 "
else
ls_filter_condition = ls_filter_condition + &
ls_column + ls_compare + "'" + ls_value + "' "
end if
case 'num','dec','lon','rea','ulo'
ls_filter_condition = ls_filter_condition + &
ls_column + ls_compare + ls_value
case 'dat','tim'
ls_filter_condition = ls_filter_condition + "string(" + &
ls_column + ", 'yyyy.mm.dd')" + &
ls_compare + "'" + ls_value + "'"
case else
end choose

else

choose case ls_column_type //根据数据类型设置Filter条件
case 'cha','var','str'
if ls_compare="==" then
ls_filter_condition = ls_filter_condition + &
"Pos(" 2B ls_column + " , '" + ls_value +"')<>0 " &
+ ls_and_or + " "
else
ls_filter_condition = ls_filter_condition + &
ls_column + ls_compare + "'" + ls_value + "' " &
+ ls_and_or + " "
end if
case 'num','dec','lon','rea','ulo'
ls_filter_condition = ls_filter_condition + &
ls_column + ls_compare + ls_value + " " &
+ ls_and_or + " "
case 'dat','tim'
ls_filter_condition = ls_filter_condition + "string(" + &
ls_column + ", 'yyyy.mm.dd')" + &
ls_compare+ "'" + ls_value+ "' " &
+ ls_and_or + " "
case else
end choose
end if
next

//messagebox('ls_filter_condition', ls_filter_condition)
0Aif ls_filter_condition = '' then return


dw_query.setredraw(false)
0Adw_query.setFilter(ls_filter_condition)
if dw_query.filter() = 1 and dw_query.rowcount() > 0 then
ls_column = dw_query_condition.getitemstring(1, 'column_name')
dw_query.setsort(ls_column + ' A')
dw_query.sort()
dw_query.SetColumn(ls_column)0D dw_query.selectrow(0,false)
dw_query.selectrow(1,true)
0Adw_query.setrow(1)
end if
dw_query.setredraw(true)
================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]0
...全文
33 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
海洋‘s 2002-05-14
  • 打赏
  • 举报
回复
通用查询的代码我给别人发过了,去找找,也许对你有用。
海洋‘s 2002-05-14
  • 打赏
  • 举报
回复
夜深了该休息了!

我这里还有通用查询的代码
andyzq 2002-05-14
  • 打赏
  • 举报
回复
用like
海洋‘s 2002-05-14
  • 打赏
  • 举报
回复
string rc, mod_string
string jyrq1,jyrq2,ghrq1,ghrq2
string str

is_where_clause =''

//井号
if len(sle_jh.text) > 0 then
is_where_clause = " where mng_zlgl.jh like " &
+ "~~~'%" + sle_jh.text + "%~~~'"
END IF

/*对起始借阅日期、最后借阅日期、起始归还日期和最后归还日起初始化*/
//起始借阅日期
if em_start1.text = '0000.00.00' or isnull(em_start1.text) then
jyrq1 = '1900.01.01'
else
jyrq1 = em_start1.text
end if
//最后借阅日期
if em_end1.text = '0000.00.00' or isnull(em_end1.text) then
jyrq2 = '2300.01.01'
else
jyrq2 = em_end1.text
end if
//起始归还日期
if em_start2.text = '0000.00.00' or isnull(em_start2.text) then
ghrq1 = '1900.01.01'
else
ghrq1 = em_start2.text
end if
//最后归还日期
if em_end2.text = '0000.00.00' or isnull(em_end2.text) then
ghrq2 = '2300.01.01'
else
ghrq2 = em_end2.text
end if

/*判断借阅日期:起始借阅日期和最后借阅日起进行对比*/
//起始借阅日期
if jyrq1 <> '1900.01.01' then
if is_where_clause <> "" then
is_where_clause = is_where_clause + " and jyrq >= to_date(~~~'" + jyrq1 + "~~~',~~~'yyyy.mm.dd~~~')"
else
is_where_clause = "where jyrq >= to_date(~~~'" + jyrq1 + "~~~',~~~'yyyy.mm.dd~~~')"
end if
end if

//最后借阅日期
if jyrq2 <> '2300.01.01' then
if is_where_clause <> "" then
is_where_clause = is_where_clause + " and jyrq <= to_date(~~~'" + jyrq2 + "~~~',~~~'yyyy.mm.dd~~~')"
else
is_where_clause = "where jyrq <= to_date(~~~'" + jyrq2 + "~~~',~~~'yyyy.mm.dd~~~')"
end if
end if


//起始归还日期
if ghrq1 <> '1900.01.01' then
if is_where_clause <> "" then
is_where_clause = is_where_clause + " and ghrq >= to_date(~~~'" + ghrq1 + "~~~',~~~'yyyy.mm.dd~~~')"
else
is_where_clause = "where ghrq >= to_date(~~~'" + ghrq1 + "~~~',~~~'yyyy.mm.dd~~~')"
end if
end if

//最后归还日期
if ghrq2 <> '2300.01.01' then
if is_where_clause <> "" then
is_where_clause = is_where_clause + " and ghrq <= to_date(~~~'" + ghrq2 + "~~~',~~~'yyyy.mm.dd~~~')"
else
is_where_clause = "where ghrq <= to_date(~~~'" + ghrq2 + "~~~',~~~'yyyy.mm.dd~~~')"
end if
end if

//开始批次em_pc1

//if len(em_pc1.text) > 0 and em_pc1.text <> '0' then
//if is_where_clause <> "" then
// is_where_clause =is_where_clause + " and to_char(mng_zlgl.pc) >= " + "~~~'" + em_pc1.text + "~~~'"
//else
// is_where_clause ="where to_char(mng_zlgl.pc) >= " + "~~~'" + em_pc1.text + "~~~'"
//end if
//END IF
//

//
if len(em_pc1.text) > 0 and em_pc1.text <> '0' then
if is_where_clause <> "" then
is_where_clause =is_where_clause + " and mng_zlgl.pc >= " + "~~~'" + em_pc1.text + "~~~'"
else
is_where_clause ="where mng_zlgl.pc >= " + "~~~'" + em_pc1.text + "~~~'"
end if
END IF


//


//最后批次em_pc2
if len(em_pc2.text) > 0 and em_pc2.text <> '0' then
if is_where_clause <> "" then
is_where_clause =is_where_clause + " and mng_zlgl.pc <= " + "~~~'" + em_pc2.text + "~~~'"
else
is_where_clause ="where mng_zlgl.pc <= " + "~~~'" + em_pc2.text + "~~~'"
end if
END IF


//资料借阅情况查询
str = ""
if cbx_wz.checked = true then
if str = "" then
str = "-1"
else
str = str + ",-1"
end if
end if

if cbx_qt.checked = true then
if str = "" then
str = "-2"
else
str = str + ",-2"
end if
end if

if cbx_ds.checked = true then
if str = "" then
str = "-3"
else
str = str + ",-3"
end if
end if

if str <> "" then
str = "in(" + str + ")"
end if

if str <> "" then
if is_where_clause <> "" then
is_where_clause =is_where_clause + " and (mng_zlgl.wjbg " + str + &
" or mng_zlgl.dcjs " + str + &
" or mng_zlgl.qcjs "+ str + &
" or mng_zlgl.syzj " + str + ")"
else
is_where_clause ="where mng_zlgl.wjbg " + str + &
" or mng_zlgl.dcjs " + str + &
" or mng_zlgl.qcjs " + str + &
" or mng_zlgl.syzj " + str
end if
end if
//messagebox('11',is_where_clause)

//对查询的条件进行综合,并且显示查询结果到数据窗口(Dw_master)

Mod_string = "DataWindow.Table.Select='"+ is_select + Is_where_clause + "'"

rc = dw_master.Modify(mod_string)

dw_master.Retrieve()
// Messagebox("符合条件的纪录共:",dw_master.RowCount(),none!)
IF rc = "" THEN
dw_master.Retrieve( )
ELSE
MessageBox("查询结果", "对不起,当前没有符合条件的记录, 试图输入其它内容进行查询!",Exclamation!)
END IF
dw_master.setfocus()

st_Hj.Text = String(dw_master.RowCount())


integer li_rowcount
li_rowcount=dw_master.rowcount()
if li_rowcount>0 then
cb_gh.enabled=true
else
end if

看看我的模糊查询代码,就是我刚做完的一个系统.请好用的.你可以将这些代码进行修改成为自己的.


1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧