回复 楼主 lifeng123
程序代码:
*--- VFP9.0 CODE
CREATE CURSOR 表A (联系人 C(6))
XM="柳银霞郑文秀徐冬瑾李胜韬张林杰刘焕丽孙静媛吴春海刘学佳门彦先甄志爽门月红"
FOR I=1 TO LENC(XM)/3
INSERT INTO 表A VALUES (SUBSTRC(XM,(I-1)*6+1,3))
ENDFOR
CREATE CURSOR 表B (联系人 C(6),地区 C(40))
XMDQ="门彦先,天津;吴春海,北京;吴春海,天津;张林杰,秦皇岛;郑文秀,唐山;郑文秀,秦皇岛;郑文秀,天津"
FOR I=1 TO GETWORDCOUNT(XMDQ,";")
XMDQ1=GETWORDNUM(XMDQ,I,";")
INSERT INTO 表B VALUES (GETWORDNUM(XMDQ1,1,","),GETWORDNUM(XMDQ1,2,","))
ENDFOR
SYS(3099,70)
SELECT A.联系人,NVL(B.地区,"") AS 地区,COUNT(地区) AS 地区数 FROM 表A A FULL JOIN 表B B ON A.联系人==B.联系人 GROUP BY 1 INTO CURSOR TEMP1
SELECT 联系人,CAST(FUN(联系人) AS C(20)) AS 地区 FROM 表B GROUP BY 1 INTO CURSOR TEMP2
SELECT A.联系人,NVL(B.地区,"") AS 地区,A.地区数 FROM TEMP1 A FULL JOIN TEMP2 B ON A.联系人==B.联系人 GROUP BY 1 INTO CURSOR TEMP READWRITE
BLANK ALL FIELDS 地区数 FOR 地区数=0
BROWSE
*--------- 自定义函数 ---------*
FUNCTION FUN
PARAMETER CNAME
CSTR=""
SELECT 表B
SCAN FOR ALLTRIM(联系人)==ALLTRIM(CNAME)
CSTR=CSTR+ALLTRIM(地区)+"-"
ENDSCAN
RETURN LEFT(CSTR,LEN(CSTR)-1)
ENDFUNC
效果图
图片附件: 游客没有浏览图片的权限,请
登录 或
注册