Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to change columns to rows in SELECT ?
Message
 
To
19/04/2001 15:35:38
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00497538
Message ID:
00497557
Views:
10
Here's a way to do it purely through a SQL statement into a cursor:
lcCode="ABC"
SELECT cDate1 AS cDate FROM mytable WHERE cCode=lcCode ;
UNION ALL ;
SELECT cDate2 AS cDate FROM mytable WHERE cCode=lcCode ;
UNION ALL ;
SELECT cDate3 AS cDate FROM mytable WHERE cCode=lcCode ;
UNION ALL ;
SELECT cDate4 AS cDate FROM mytable WHERE cCode=lcCode ;
UNION ALL ;
SELECT cDate5 AS cDate FROM mytable WHERE cCode=lcCode ;
UNION ALL ;
SELECT cDate6 AS cDate FROM mytable WHERE cCode=lcCode ;
HAVING EMPTY(cDate)=.F. ;
INTO CURSOR result
The HAVING eliminates any blank data in the cDate fields.

A better way, I think, is to SELECT...INTO ARRAY first and then create a cursor on your own and load it from the array:
SELECT ;
  cDate1,cDate2,cDate3,cDate4,cDate5,cDate6 ;
FROM ;
  mytable ;
WHERE ;
  cCode="ABC" ;
INTO ;
  ARRAY myarray
*
* At this point the array is dimensioned as [1,6]
* We'll change rows to columns and vice-versa... i.e., a [6,1]
*
DIMENSION myarray[6,1]

CREATE CURSOR mycursor (cDate c(10))
APPEND FROM ARRAY myarray
You can add code to eliminate blanks if there are any.

(If this message solved your problem, please click on the "Mark this message as the answer to the thread" hyperlink below... Thanks).

--Brad
Previous
Reply
Map
View

Click here to load this message in the networking platform