当前位置:主页>销售管理软件> 列表

高手请进,SQL的问题 找初级会计电算化软件

销售管理软件版1楼: 有3个查询条件,小弟写了以下的代码,但只有第一个IF语句起作用,即只有当edit1,edit2,edit3全部有内容时,才起作用。请教大家,到底是哪里的语句需要修改?谢谢
if edit1.Text<>'''' then
if edit2.Text<>'''' then
if edit3.Text<>'''' then
if radiobutton1.Checked=true then
h:=(''and c.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%''''''+''and a.lotno like ''''%''+edit3.Text+''%'''''')
else
h:=(''and b.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%''''''+''and a.lotno like ''''%''+edit3.Text+''%'''''')
else if edit1.Text<>'''' then
if edit2.Text<>'''' then
if radiobutton1.Checked=true then
h:=(''and c.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%'''''')

else
h:=(''and b.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%'''''')
else
h:=(''and d.corppn like ''''%''+edit1.text+''%'''''')
else if edit1.Text<>'''' then
if edit3.Text<>'''' then
h:=(''and d.corppn like ''''%''+edit1.Text+''%''''''+''and a.lotno like ''''%''+edit3.Text+''%'''''')
else
h:=(''and d.corppn like ''''%''+edit1.text+''%'''''')
else
h:='''';

2楼: 这样写代码自己都会晕的
按我的建议先做修改
if edit1.Text='''' then
EXIT;//退出程序
其他同理 如免费局域网管理软件

3楼: 强人啊

4楼: 感谢Johnny_du和SiWeiLiuLang两位的热心帮助,小弟再次表示感激!--redjack_king

你可以用循环检查Box来处理该语句,本人以前做过类似这样的SQL语句,而且很直观。

5楼: 楼主的代码我快晕了,同意楼上那位大位的说法


楼主应该采取其他办法

6楼: 楼主,建议用Case。。。of 语句来写,这样条理比较清楚一点,你的代码看了很头晕,不太好读!!!

销售管理软件版7楼: 谢谢

8楼: 1.如果用IF条件语名,建议用and的形式把条件连起来。
2.IF语名最好加上BEGIN..END,看起来会清晰点。
3.找问题用逐步追踪,看看到底执行到哪条语句去了。

9楼: 先把结构理顺后,再不行,发出来,大家帮你找错误
否则这么帮你找,要累死人的

10楼: 好象是组合查询的!
说实话这样的查询写法太叫人晕了。

11楼: 你这段语句写得太差,写程序时不要想一步到位,要分而置之的分析方法想问题。
我想我这段可以符合你的要求:
h := ''''
if Edit1.Text <>'''' then
h := h+ ''and d.corppn like ''''%'' + edit1.text + ''%'''''';
if Edit2.Text <>'''' then
if radiobutton1.Checked = true then
h := h+''and c.techname like ''''%'' + edit2.Text + ''%''''''
else
h := h+ ''and b.techname like ''''%'' + edit2.Text + ''%'''''';
if Edit3.Text <>'''' then
h := h+''and a.lotno like ''''%'' + edit3.Text + ''%'''''';

12楼: lz你写的代码是只有当edit1,edit2,edit3全部有内容时,才起作用啊,对的啊,你想要得到什么样的结果嘛,把需求说清楚点嘛,应该是个简单问题吧,不要着急,静下心整理下思路就ok了 如初级会计电算化软件

13楼: if (edit1.Text<>'''') and (edit2.Text<>'''') and (edit3.Text<>'''') then

销售管理软件版14楼: 你的代码可读性差,优化一下啊!

15楼: 你可以定义一个过程啊~!~!~!~到时候调用一下这个过程啊 `!~!~


也不会重复的写啊~!~!多方便啊~!~

16楼: if (edit1.text<>'''') and (edit2.text<>'''') and .... then
begin


end;
不就完事了?

17楼: 电脑没有错呀!!!!!
也的确只有当edit1,edit2,edit3全部有内容时,才起作用。
if edit1.Text<>'''' then
if edit2.Text<>'''' then
if edit3.Text<>'''' then
//////////////这里开始
if radiobutton1.Checked=true then
h:=(''and c.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%''''''+''and a.lotno like ''''%''+edit3.Text+''%'''''')
else
h:=(''and b.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%''''''+''and a.lotno like ''''%''+edit3.Text+''%'''''')
else if edit1.Text<>'''' then
if edit2.Text<>'''' then
if radiobutton1.Checked=true then
h:=(''and c.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%'''''')


else
h:=(''and b.techname like ''''%''+edit2.Text+''%''''''+''and d.corppn like ''''%''+edit1.text+''%'''''')
else
h:=(''and d.corppn like ''''%''+edit1.text+''%'''''')
else if edit1.Text<>'''' then
if edit3.Text<>'''' then
h:=(''and d.corppn like ''''%''+edit1.Text+''%''''''+''and a.lotno like ''''%''+edit3.Text+''%'''''')
else
h:=(''and d.corppn like ''''%''+edit1.text+''%'''''')
//////////////////到这里都是属于一句
///也就是属于if edit1.Text<>'''' then
// if edit2.Text<>'''' then
// if edit3.Text<>'''' then
//的判断内
else
h:='''';
请优化你的代码吧,可读性很差
一定要这样,我建议从单个条件到两个条件到三个条件这样判断会好一些

18楼: 非常感谢大家对小弟的支持与帮助,对组合查询条件的编写令小弟我明白程序代码的可读性的重要。谢谢大家

19楼: 不客气,问题解决了没有?


没有的话,把修改后的语句贴出来
解决的话,把帖子结了

20楼: 谢谢大家