请教,如何编程把表tt1变成表tt2?
请教老师,如何编程把表tt1变成表tt2,感谢
Creat table tt1 (cname c(10), date1 d (8),date2 d(8),salary n(9,2))
INSERT INTO tt1 VALUES ("mimi",{^2006/1/1},{^2007/2/28},2050)
INSERT INTO tt1 VALUES ("cici",{^2005/11/1},{^2007/8/30},2300)
Brow
Tt2
Cname cyear cmonth salary
Mimi 2006 1 2050
Mimi 2006 2 2050
Mimi 2006 3 2050
Mimi 2006 4 2050
Mimi 2006 5 2050
Mimi 2006 6 2050
Mimi 2006 7 2050
Mimi 2006 8 2050
Mimi 2006 9 2050
Mimi 2006 10 2050
Mimi 2006 11 2050
Mimi 2006 12 2050
Mimi 2007 1 2050
Mimi 2007 2 2050
Cici 2005 11 2300
Cici 2005 12 2300
Cici 2006 1 2300
Cici 2006 2 2300
Cici 2006 3 2300
Cici 2006 4 2300
Cici 2006 5 2300
Cici 2006 6 2300
Cici 2006 7 2300
Cici 2006 8 2300
Cici 2006 9 2300
Cici 2006 10 2300
Cici 2006 11 2300
Cici 2006 12 2300
Cici 2007 1 2300
Cici 2007 2 2300
Cici 2007 3 2300
Cici 2007 4 2300
Cici 2007 5 2300
Cici 2007 6 2300
Cici 2007 7 2300
Cici 2007 8 2300
[解决办法]
Close DatabasesCreate table tt1 (cname c(10), date1 d (8), date2 d(8), salary n(9,2))INSERT INTO tt1 VALUES ("mimi",{^2006/1/1},{^2007/2/28},2050)INSERT INTO tt1 VALUES ("cici",{^2005/11/1},{^2007/8/30},2300)Create table tt2 (cname c(10), cyear c(4), cmonth c(2), salary n(9,2))Select tt1Scan all Scatter name oRec ns = oRec.date1 ce = Left(Dtos(oRec.date2), 6) Do while Left(Dtos(ns), 6) <= ce Insert into tt2 (cname, cyear, cmonth, salary) Values ( ; oRec.cname, Transform(Year(ns)), Transform(Month(ns)), oRec.salary) ns = Gomonth(ns, 1) EndDoEndScanSelect tt2Browse
[解决办法]
这个问题原来问过吧,
1、生成2005-2011所有年份,用连接解决;
2、用代码解决
SET SAFETY OFF
SET DATE TO ansi
Close Databases
Create table tt1 (cname c(10), date1 d (8), date2 d(8), salary n(9,2))
INSERT INTO tt1 VALUES ("mimi",{^2006/1/1},{^2007/2/28},2050)
INSERT INTO tt1 VALUES ("cici",{^2005/11/1},{^2007/8/30},2300)
Create table tt2 (cname c(10), cyear c(4), cmonth c(2), salary n(9,2))
SELECT tt1
GO 1
scan
z1=date1
z2=date2
z3=salary
z4=cname
DO WHILE z1<= z2
Insert into tt2 (cname, cyear, cmonth, salary) Values (z4,tRANSFORM(YEAR(z1)),TRANSFORM(MONTH(z1)),z3)
z1=GOMONTH(z1,1)
ENDDO
ENDSCAN
[解决办法]
Close Databases AllCreate Table tt1 (cname c(10), date1 d (8), date2 d(8), salary N(9,2))Insert Into tt1 Values ("mimi",{^2006/1/1},{^2007/2/28},2050)Insert Into tt1 Values ("cici",{^2005/11/1},{^2007/8/30},2300)Create Table tt2 (cname c(10), cyear c(4), Cmonth c(2), salary N(9,2))Select tt1Scan All ldDate=tt1.date1 Do While ldDate<=tt1.date2 Insert Into tt2 (cname, cyear, Cmonth, salary) Values ( ; tt1.cname, Transform(Year(ldDate)), Transform(Month(ldDate)), tt1.salary) ldDate = Gomonth(ldDate, 1) EnddoEndscanSelect tt2LocateBrowse