新手求教SQL查询

恶鱼 2004-07-31 01:31:49
有一张表A,里面的数据项是C,D,E,F,G
我想用一个界面,里面分别入SLE_1至SLE_5 。完成的功能是
当用户真写任意一个SLE_1时,完成相应的查询,返回符合条件的所有项,
比如
用户在SLE_1中填1
生成语句为select * from A where SLE_1=1
用户在SLE_1和SLE_2,各填写 2。 3
生成语句为select * from A where SLE_1=2and SLE_2=3

在DELPHI中我能实现了 刚刚学PB无从下用了。
大家帮一下我



...全文
80 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
duanhuicen 2004-07-31
  • 打赏
  • 举报
回复
刚才写错了
重发

string sqlstr,wherestr
sqlstr="select * from biao where 1=1"
wherestr=""
if sle_1.text<>"" then
wherestr=wherestr+" and a="+sle_1.text
end if
if sle_2.text<>"" then
wherestr=wherestr+" and b="+sle_2.text
end if
if sle_3.text<>"" then
wherestr=wherestr+" and c="+sle_3.text
end if
if sle_4.text<>"" then
wherestr=wherestr+" and d="+sle_4.text
end if
sqlstr=sqlstr+wherestr
sle_5.text=sqlstr
duanhuicen 2004-07-31
  • 打赏
  • 举报
回复
string sqlstr,wherestr
sqlstr="select * from biao where 1=1"
wherestr=""
if sle_1.text<>"" then
wherestr=wherestr+" and a="+sle_1.text
end if
if sle_2.text<>"" then
wherestr=wherestr+" and b="+sle_1.text
end if
if sle_3.text<>"" then
wherestr=wherestr+" and c="+sle_1.text
end if
if sle_4.text<>"" then
wherestr=wherestr+" and d="+sle_1.text
end if
sqlstr=sqlstr+wherestr
sle_5.text=sqlstr
sywen 2004-07-31
  • 打赏
  • 举报
回复
string ls_sql,ls_condition
string ls_1,ls_2,ls_3,ls_4,ls_5
ls_1=trim(sle_1.text)
....
ls_5=trim(sle_1.text)

if len(ls_1)>0 then
ls_conditon=ls_conditon+ " and sle_1='"+ls_1+"'"
end if
......

if len(ls_5)>0 then
ls_conditon=ls_conditon+ " and sle_5='"+ls_5+"'"
end if
if len(ls_condition)>0 then
ls_condition=mid(ls_condition,pos(ls_condition,'and')+3)
end if
ls_sql=+select * from A where "+ls_condition

waterloocsdn 2004-07-31
  • 打赏
  • 举报
回复
sle_1的modified事件中:
if isnull(sle_1.text) then
return
else
select * from A where 字段1=:SLE_1.text using 事务对象名;
end if

sle_2的modified事件中:
if isnull(sle_2.text) then
return
else
select * from A where 字段1=:SLE_1.text and 字段2=:SLE_2.text using 事务对象名;
end if
恶鱼 2004-07-31
  • 打赏
  • 举报
回复
还是要谢谢你
不过我不是要这个结果
我是要一个动态的SQL写法
下面我只是举一个例子
就像是
DELPHI中
QUERY的用法一样我能一条一条加WHERE的的条件
PB中怎么实现
lzheng2001 2004-07-31
  • 打赏
  • 举报
回复
A,B,C,D,E列为字符型列

select * from A where A = :SLE_1.text and B=:sle_2.text
using sqlca;
恶鱼 2004-07-31
  • 打赏
  • 举报
回复
大家帮一下我啊
在线等

1,072

社区成员

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

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