按单位,姓名转行
姓名列转行如附件,将表的姓名列转成行,姓名有很多行。想每20个姓名转成一行,且每个姓名之间加“,”英文逗号。如何实现?
谢谢!!!
以前发过贴,现增加按单位分字段,求助!
附表,附原代码
姓名列转行.rar
(392 Bytes)
CLOSE TABLES all SELECT 单位 dwmc,SPACE(LEN(姓名)*20) xm FROM 姓名列转行 INTO dbf zgmd WHERE .f. SELECT distinc 单位 as dwmc FROM 姓名列转行 INTO CURSOR dwtmp SCAN _dwmc=ALLTRIM(dwmc) select 姓名 as xm from 姓名列转行 INTO CURSOR xmtmp where ALLTRIM(单位)==_dwmc fzs=CEILING(RECCOUNT('xmtmp')/20)-1 FOR i=0 TO fzs SELECT xmtmp GO i*20+1 _xm='' j=0 DO WHILE !EOF() AND j<20 _xm=_xm+','+ALLTRIM(xm) skip ENDDO INSERT INTO zgmd (dwmc,xm) VALUES (_dwmc,SUBSTR(_xm,2)) ENDFOR ENDSCAN
[此贴子已经被作者于2021-9-28 19:10编辑过]
CLOSE DATABASES USE xx IN 0 ALIAS bj CREATE CURSOR test (bj c(10), xm c(150)) SELECT 班级名称 bjmc, COUNT(*) rs FROM xx GROUP BY 1 INTO CURSOR bjmc lnR = 20 SCAN lnC = 0 lnCnt = 0 lcXm = "" SELECT bj SCAN FOR ALLTRIM(班级名称) == ALLTRIM(bjmc.bjmc) lnC = lnC + 1 lcXm = lcXm - "," - 姓名 IF lnC = bjmc.rs OR lnC % lnR = 0 lnCnt = lnCnt + 1 INSERT INTO test VALUES (ALLTRIM(bj.班级名称) + "_" + TRANSFORM(lnCnt), SUBSTR(lcXm, 2)) lcXm = "" ENDIF ENDSCAN ENDSCAN SELECT test BROWSE
[此贴子已经被作者于2021-9-29 00:11编辑过]