同时查询时间型和字符型

blackman41 2008-09-03 10:43:08
这是我调试后的结果:帐号='1111111111111111111'or 帐号='1111111111111111112'or 帐号='1234567891234567891'or 帐号='1111111111111111111'and 交易时间=2008-2-2
就是说对上面这语句进行setfilter()后报错,expression is not valid
问题是:我对数值型和字符型一起查找时,是可以的.如上面把and 交易时间=2008-2-2替成数量等于20.
我的目的是这样的,要把dw_3的窗口已经查询好的条件做为基础,然后再加个查询.并显示在dw_3上.
注:我已经用过SQL的方法了,只是老报where附近出错.所以我就放弃了,用这种方法试试.

下面是我目前的代码:______________________________________________________________________
if sle_2.text="" then
messagebox("注意!","请输入查找开始月份!")
else
//定义参数:查条件综合结果
string LookforCondition2,lookforcondition1,lookforcondition3,lookfrocondition4
//定义参数:要查询的列
string LookforItem,lookforhow1,lookforhow2
//定义参数:要查询的内容
string LookforWhat2,lookforwhat1
//定义参数:总的行数
int total_row
string all_col[]
string lookforallitem1,lookforallitem2
int i
total_row=dw_3.rowcount()
if total_row=0 then
messagebox("注意","已经没有可查询数据!")
else
for i=1 to total_row
all_col[i]=dw_3.getitemstring(i,1)
next
lookforallitem2="编号"+"="+"'"+all_col[1]+"'"
i=2
do while i <=total_row
lookforallitem1="编号"+"="+"'"+string(all_col[i])+"'"
lookforallitem2=lookforallitem2+"or"+" "+lookforallitem1
i=i+1
loop

//查询子段和查询内容的选择
lookforcondition3="月份"+">="+""+string(lookforwhat1)+""
lookfrocondition4="月份"+" <="+""+string(lookforwhat2)+""
lookforcondition1=lookfrocondition4+"and"+" "+lookforcondition3
lookforCondition2=lookforallitem2+"and"+" "+lookforcondition1
//定义读者编号
//过滤数据窗口dw_1
dw_3.setfilter(lookforCondition2)
filter(dw_3)
...全文
187 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sun1976 2008-09-11
  • 打赏
  • 举报
回复
改为拼出这么个字符串来过滤
( …… or 帐号= '1111111111111111111')and string(交易时间,'yyyy-m-d')='2008-2-2'
我没仔细写,抱歉
我的意思是你前面或者关系的条件应该用括号括起来再和and拼接
blackman41 2008-09-05
  • 打赏
  • 举报
回复
但是如果是( …… or '1111111111111111111')and 交易时间='2008-2-2'
这样是不行的.
blackman41 2008-09-05
  • 打赏
  • 举报
回复
都可以啊.但是'月份'表中是时间型啊.怎么转换啊.如何让lookforwhat加上引号啊!
lookforcondition="月份"+"="+""lookforwhat""对吗?
sun1976 2008-09-05
  • 打赏
  • 举报
回复
不知道为什么不试我的方法
blackman41 2008-09-05
  • 打赏
  • 举报
回复
唉呀,怎么都没人理啊.问题应该不算太难吧!急啊,程序就剩这一点没解决了.
sun1976 2008-09-04
  • 打赏
  • 举报
回复
改为拼出这么个字符串来过滤
( …… or '1111111111111111111')and string(交易时间,'yyyy-m-d')='2008-2-2'
-狙击手- 2008-09-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 pcwe2002 的回复:]
帐号='1111111111111111111'and 交易时间='2008.2.2'
[/Quote]
liubocy 2008-09-04
  • 打赏
  • 举报
回复
这要看你数据库中交易时间是个什么类型的字段,如果是日期型的,可以用
convert( char(10), 交易时间, 120 ) = '2008-02-02'

如果是char、varchar型的,用substring函数来匹配字符串
pcwe2002 2008-09-04
  • 打赏
  • 举报
回复
帐号='1111111111111111111'and 交易时间='2008.2.2'
ybkenan 2008-09-04
  • 打赏
  • 举报
回复
樓主代碼寫得太亂了。要好好規范一下。 ^_^
報錯原因是字符型和日期型不匹配。查看一下PB中怎樣把日期轉為字符的。
建議最好用SQL語句寫這類查詢。
blackman41 2008-09-04
  • 打赏
  • 举报
回复
调试我试过了六楼的方法.能行...只是小弟不懂.要怎么实现.
交易时间的字段在表中是datetime类型了.( 用sql200)
而装2008-2-2的是sle_3.text
如果用lookforwhat=等于sle_3.text,那么怎么定义lookforwhat这个变量.
最后的问题,用lookforcondition="月份"+"="+"'"+lookforwhat"'" 这样对吗?
如果dw_.setfilter(lookforCondition) 这个lookforcondition定义成string行吗?
blackman41 2008-09-04
  • 打赏
  • 举报
回复
谢谢提醒啊.只是怎么规范啊!我刚学PB还没两周很多都不懂哦!
sanmao136 2008-09-04
  • 打赏
  • 举报
回复
filter条件:
帐号='1111111111111111111'or 帐号='1111111111111111112'or 帐号='1234567891234567891'or 帐号='1111111111111111111'and date(交易时间)=date('2008-2-2')

609

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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