Article ID: 191529
Article Last Modified on 3/3/2005
CLOSE ALL
CREATE TABLE bldg1 (sid c(5), busnum c(3))
CREATE TABLE main (name c(10), sid c(5), busnum c(3))
* Insert records into main with bus number matching
* last two digits of student's id.
SELECT main
FOR i = 20 to 30
INSERT INTO main (name, sid, busnum);
VALUES (SYS(2015), "888"+ALLTRIM(STR(i)), ALLTRIM(STR(i)))
ENDFOR
* Insert records into bldg1 with single digit bus number.
SELECT bldg1
FOR i = 20 to 30
INSERT INTO bldg1 (sid, busnum);
VALUES ("888"+ALLTRIM(STR(i)), ALLTRIM(STR(i/10)))
ENDFOR
BROWSE
* Modify records in bldg1 table to be the same as those in main.
SELECT main
SCAN
UPDATE bldg1 ;
SET bldg1.busnum = main.busnum ;
WHERE bldg1.sid = main.sid
ENDSCAN
SELECT bldg1
BROWSE
CLOSE ALL
CREATE TABLE bldg1 (sid c(5), busnum c(3))
CREATE TABLE main (name c(10), sid c(5), busnum c(3))
* Insert records into main with bus number matching
* last two digits of student's id
SELECT main
FOR i = 20 to 30
INSERT INTO main (name, sid, busnum);
VALUES (SYS(2015), "888"+ALLTRIM(STR(i)), ALLTRIM(STR(i)))
ENDFOR
SELECT main
INDEX ON sid TAG sid OF main
* Insert records into bldg1 with single digit bus number.
SELECT bldg1
FOR i = 20 to 30
INSERT INTO bldg1 (sid, busnum);
VALUES ("888"+ALLTRIM(STR(i)), ALLTRIM(STR(i/10)))
ENDFOR
SELECT bldg1
INDEX ON sid TAG sid OF bldg1
BROWSE
* Modify records in bldg1 table to be the same as those in main.
SELECT bldg1
SET ORDER TO TAG sid
SELECT main
SET ORDER TO TAG sid
SET RELATION TO sid INTO bldg1
SET SKIP TO bldg1
GO TOP
REPLACE bldg1.busnum WITH main.busnum WHILE !EOF()
SELECT bldg1
BROWSE
CLOSE ALL
CREATE TABLE bldg1 (sid c(5), busnum c(3))
CREATE TABLE main (name c(10), sid c(5), busnum c(3))
* Insert records into main with bus number matching
* last two digits of student's id
SELECT main
FOR i = 20 to 30
INSERT INTO main (name, sid, busnum);
VALUES (SYS(2015), "888"+ALLTRIM(STR(i)), ALLTRIM(STR(i)))
ENDFOR
SELECT main
INDEX ON sid TAG sid OF main
* Insert records into bldg1 with single digit bus number.
SELECT bldg1
FOR i = 20 to 30
INSERT INTO bldg1 (sid, busnum);
VALUES ("888"+ALLTRIM(STR(i)), ALLTRIM(STR(i/10)))
ENDFOR
SELECT bldg1
INDEX ON sid TAG sid OF bldg1
BROWSE
* Modify records in bldg1 table to be the same as those in main.
SELECT main
SET ORDER TO TAG sid
SELECT bldg1
SET ORDER TO TAG sid
SET RELATION TO sid INTO main
UPDATE bldg1 SET bldg1.busnum = main.busnum
SELECT bldg1
BROWSE
Additional query words: two tables
Keywords: kbhowto kbxbase KB191529