以下是引用zpeter1991在2018-10-13 21:39:39的发言:
版主们好,我测试过了,是这个效果。但工作上我随时需要复查材质和颜色,或形号和颜色,所以希望可以键入如135和BK,就可以单独显示出所有135,BK的存货,又如键入CO和BU,就可以单独显示出所有CO,BU的存货。麻烦你们了!
*!* 建立测试数据
CREATE CURSOR 存货(入庫号 C(3),形号 C(3),材质 C(2),颜色 C(2))
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('100','136','CO','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('101','136','TU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('102','138','CO','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('103','138','MU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('104','221','CO','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('105','221','MU','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('106','135','CO','BU')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('107','135','CO','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('108','222','TU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('109','222','TU','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('110','222','MU','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('111','223','TU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('112','221','MU','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('113','221','CO','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('114','136','TU','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('115','136','CO','BU')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('116','138','MU','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('117','135','TU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('118','223','CO','BU')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('119','223','CO','BK')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('120','222','MU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('121','330','TU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('122','330','MU','RE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('123','331','TU','YE')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('124','335','FE','BU')
INSERT INTO 存货(入庫号,形号,材质,颜色) VALUES ('125','335','TU','BU')
*!* 动态查询
Local lc形号,lc材质,lc颜色,lcWhere
lc形号 = ALLTRIM(Thisform.text1.value)
lc材质 = ALLTRIM(Thisform.text2.value)
lc颜色 = ALLTRIM(Thisform.text3.value)
lcWhere = ""
If !Empty(lc形号) &&如果形号条件不空,有输入数据
lcWhere = "ALLTRIM(形号)==lc形号"
EndIf
If !Empty(lc材质) &&如果材质条件不空,有输入数据
lcWhere = Iif(Empty(lcWhere),"ALLTRIM(材质)==lc材质",lcWhere + " and ALLTRIM(材质)==lc材质")
EndIf
If !Empty(lc颜色) &&如果颜色条件不空,有输入数据
lcWhere = Iif(Empty(lcWhere),"ALLTRIM(颜色)==lc颜色",lcWhere + " and ALLTRIM(颜色)==lc颜色")
EndIf
If !Empty(lcWhere) &&如果查询条件不空,形号,材质,颜色,任何一个有数据
lcWhere = " where "+ lcWhere
EndIf
Text To lcSql TEXTMERGE NOSHOW PRETEXT 4
select 入庫号,形号,材质,颜色 from 存货 <<lcWhere>> ;
order by 形号,材质,颜色
EndText
*!* 观察一下动态语句是什么样子的
?lcSql
*!* 执行动态查询
EXECSCRIPT(lcSql)