Re: Alter Table question by Stephen
Stephen
Sun Jan 14 13:39:13 CST 2007
Many thanks indeed Alders - I had to alter group char(5) to group char(6)
to get the example to work, but a completely different way of tackling the
problem. I had forgotten all about _genxtab.
Sincerely
Stephen
"Anders Altberg" <A@A> wrote in message
news:%230EaZPAOHHA.448@TK2MSFTNGP04.phx.gbl...
> CREATE CURSOR people (name char(2), fk Int)
> INSERT INTO people VALUES ('aa', 1)
> INSERT INTO people VALUES ('bb', 1)
> INSERT INTO people VALUES ('aa', 1)
> INSERT INTO people VALUES ('aa', 2)
>
> CREATE CURSOR Groups (pk Int, group Char(5) )
> INSERT INTO Groups VALUES (1, 'group1')
> INSERT INTO Groups VALUES (2, 'group2')
>
> SELECT People.name AS name, Groups.group,'X';
> FROM People JOIN Groups ON People.fk = Groups.pk ;
> GROUP BY 1,2 ORDER BY 1,2 ;
> INTO CURSOR Q1
>
> DO (_Genxtab) WITH 'Matrix'
> BROWSE LAST NOWAIT
>
> Result:
> Name Group1 Group2
> aa X X
> bb X
>
> -Anders
>
>
> "Stephen Ibbs" <stephen@ibbs.org.uk> skrev i meddelandet
> news:OqiO5$pNHHA.4912@TK2MSFTNGP02.phx.gbl...
>> Thanks Cindy - I had grossly simplified the problem. Imagine two tables
>> People and Group where people belong to different groups. The people
>> table has a foreign key into the lookup table of groups. I want to create
>> a matrix grid with people in the rows, and each groups a separate column
>> with e.g. an 'X' in each column to show which person is in each group. I
>> was creating a cursor of people and then planned to scan through the
>> lookup list and add a field for each group to the people cursor. It was
>> then a simple matter to add the 'X's as appropriate. I ran into the
>> problem when trying to add the fields, reduced the code all down and then
>> wondered whether it was because it was a cursor not a table.
>>
>> Sincerely
>>
>> Stephen
>>
>> "Cindy Winegarden" <cindy@cindywinegarden.com> wrote in message
>> news:%23QpPX9mNHHA.4244@TK2MSFTNGP04.phx.gbl...
>>> Hi Stephen,
>>>
>>> Does this work for you:
>>>
>>> Select cFamilyname, Space(20) As Anything ;
>>> from People into cursor Trythis Readwrite
>>>
>>> --
>>> Cindy Winegarden MCSD, Microsoft Most Valuable Professional
>>> cindy@cindywinegarden.com
>>>
>>>
>>>>>> Does ALTER TABLE work with cursors as well as tables? The following
>>>>>> two lines:
>>>>>>
>>>>>> Select cFamilyname from People into cursor Trythis Readwrite
>>>>>> Alter table Trythis add column Anything C(20)
>>>
>>>
>>
>>
>
>