Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Widen number of records by field
Message
 
 
To
03/11/2009 05:32:52
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01432871
Message ID:
01432879
Views:
79
Hi Agnes,

Try
* Assuming you don't have deleted records in curTable 
SELECT cTableNumber, cTableNumber + "." + TRANSFORM(sn) AS cChairNumber ;
FROM curTable ;
	JOIN ( ;
			SELECT RECNO() AS sn FROM curTable ;
			UNION ALL ;
			SELECT RECNO() + RECCOUNT() AS sn FROM curTable ) crsNumbers ON curTable.iChair >= crsNumbers.sn
The inner select with UNION creates a Numbers table. You can create it any way that works for you. Just make sure that it hold sequential whole numbers with max value not less than # of chairs. For example
* Create numbers table
lnMaxChairs = 8
CREATE CURSOR crsNumbers (sn i)
FOR i=1 TO lnMaxChairs
	INSERT INTO crsNumbers VALUES(i)
ENDFOR
	
SELECT cTableNumber, cTableNumber + "." + TRANSFORM(sn) AS cChairNumber ;
FROM curTable ;
	JOIN crsNumbers ON curTable.iChair >= crsNumbers.sn
>
>I have a new SQL riddle to solve.
>
>Given is a cursor
>
>CREATE CURSOR curTable (cTableNumber, iChair)
>INSERT INTO curTable VALUES ('1',4)
>INSERT INTO curTable VALUES ('2',3)
>INSERT INTO curTable VALUES ('3',2)
>INSERT INTO curTable VALUES ('4',6)
>
>
>Now I need to number the Chairs like 1.1,1.2,1.3,1.4 and a recors for each chair
>
>Result
>
>CREATE CURSOR curChair (cTableNumber, cChairNumber)
>INSERT INTO curTable VALUES ('1',"1.1")
>INSERT INTO curTable VALUES ('1',"1.2")
>INSERT INTO curTable VALUES ('1',"1.3")
>INSERT INTO curTable VALUES ('1',"1.4")
>INSERT INTO curTable VALUES ('2',"2.1")
>INSERT INTO curTable VALUES ('2',"2.2")
>INSERT INTO curTable VALUES ('2',"2.3")
>INSERT INTO curTable VALUES ('3',"3.1")
>INSERT INTO curTable VALUES ('3',"3.2")
>INSERT INTO curTable VALUES ('4',"4.1")
>INSERT INTO curTable VALUES ('4',"4.2")
>INSERT INTO curTable VALUES ('4',"4.3")
>INSERT INTO curTable VALUES ('4',"4.4")
>INSERT INTO curTable VALUES ('4',"4.5")
>INSERT INTO curTable VALUES ('4',"4.6")
>
>
>So how can I use SELECT SQL to achive this? I know I can SCAN and INSERT (etc.), but this is not my problem.
>
>Agnes
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform