错在哪里?请高手-----------------------
有表aa,字符型字段zh、xm、cjx,数值型字段cj,如下:
xh xm cjx cj
01119000 杨 Y601 86.00
01119000 杨 Y602 83.00
01119000 杨 Y603 77.00
01119000 杨 Y600 246.00
01119002 郭 Y102 55.00
01119002 郭 Y101 54.00
01119002 郭 Y100 109.00
01119005 赵 Y601 100.00
01119005 赵 Y602 39.00
01119005 赵 Y600 139.00
想变成表bb这样:
xh xm Y601 Y602 Y603 Y600 Y101 Y102 Y100
01119000 杨 86.00 83.00 77.00 246.00
01119002 郭 54.00 55.00 109.00
01119005 赵 100.00 39.00 139.00
下面这段代码哪里错了?Store '' To m.lcStr1,m.lcStr2
Select Distinct cjx Into Cursor T1 From aa Order By cjx
m.lcStr1="Select xh,xm,wj"
Select t1
Scan
m.lcStr1=m.lcStr1+",Iif(Alltrim(cjx)=='"+Alltrim(T1.cjx)+"',cj,0000) As cj"+Alltrim(T1.cjx)
Endscan
m.lcStr1=m.lcStr1+" Into Table bb.dbf From aa"
&lcStr1.
Select t1
Scan
m.lcStr2="Blank Fields cj"+Alltrim(T1.cjx)+" All For cj"+Alltrim(T1.cjx)+"=0"
Select bb
&lcStr2.
Endscan
Select bb
Browse
[解决办法]
示例
自行修改
SELECT distinct cjx FROM r:\temp\ttg INTO CURSOR ss
a=''
SCAN
a=a+'sum(IIF(cjx="'+cjx+'",cj,0000000.00)) as '+cjx+','
ENDSCAN
a='select xh,xm,'+LEFT(a,LEN(a)-1)+' from ttg group by xh,xm'
&a
[解决办法]
加个 Sum
Store '' To m.lcStr1,m.lcStr2
Select Distinct cjx Into Cursor T1 From aa Order By cjx
m.lcStr1="Select xh,xm"
Select t1
Scan
m.lcStr1=m.lcStr1+",Sum(Iif(Alltrim(cjx)=='"+Alltrim(T1.cjx)+"',cj,0000.00)) As "+Alltrim(T1.cjx)
Endscan
m.lcStr1=m.lcStr1+" Into Table bb.dbf From aa group by xh,xm"
&lcStr1.
Select t1
Scan
m.lcStr2="Blank Fields "+Alltrim(T1.cjx)+" All For "+Alltrim(T1.cjx)+"=0"
Select bb
&lcStr2.
Endscan
Select bb
Browse