Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create n sql columns dynamically
Message
From
04/07/2001 05:31:19
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00526094
Message ID:
00526617
Views:
18
Oops, sorry, uit should be another way:

lcstr=

select a1.id, min(a1.time) as m1, min(a2.time) as m2, min(a3.time) as m3, ..... from MyTimes a1
INNER JOIN MyTimes a2 ON a1.id=a2.id AND a2.time>a1.time
INNER JOIN MyTimes a3 ON a2.id=a3.id AND a3.time>a2.time
....
group by ID
into cursor tempcursor

HTH.


>Hi!
>
>You can do this by using & and SELECT statements. Populate a string variable with the query like following:
>
>lcstr=
>
>select a1.id, a1.time as m1, 0 as m2, 0 as m3, ..... from MyTimes a1 into cursor tempcursor
>union all
>select a2.id, 0 as m1, a2.time as m2, 0 as m3, ..... from MyTimes a2
>union all
>select a3.id, 0 as m1, 0 as m2, a3.time as m3, ..... from MyTimes a3
>.....
>
>&lcstr
>
>Next query is:
>
>select id, max(m1), max(m2), max(m3), ..... from tempcursor group by id
>
>Build it in the string and run it too using &. Instead of max() you can use sum() in case of negative values, it is slower, however.
>
>Pretty pure crosstab, but in simple case it is just a 2 queries...
>
>HTH.
>
>>Hi readers!,
>> Is it possible to create n sql columns for an specific field table, let me explain a little bit more:
>>
>> I have the next table:
>> field -----value
>> id ---- 1000
>> time ---- 0700
>> id ---- 1000
>> time ---- 1700
>> id ---- 1400
>> ...and so on
>>
>>and I need the syntax for sql command that produces the next result set:
>>
>> id ------ m1 --- m2 --- m3 ... mn
>> 1000 -- 0700 -- 1400 -- 1700 ...
>>
>>Best Regards
>>Martin Alcaraz
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Reply
Map
View

Click here to load this message in the networking platform