Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Aways get a 3x3 array from a SQlL select command
Message
From
14/05/2003 11:43:13
 
 
To
14/05/2003 08:54:46
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00788138
Message ID:
00788218
Views:
14
Claude,

If you have a lot of records in your table, this should be faster than Cetin's idea. This assumes you have an index on your date field. In this example I renamed a couple of fields that were reserved keywords.

I tried to do a join (similar to Sergey's suggestion), but didn't get one to work properly.
create cursor empties (priKey c(4), valuea i, valueb i)
insert into empties (prikey) values ("key1")  && replace this with the correct 3 possible keys
insert into empties (prikey) values ("key2")
insert into empties (prikey) values ("key3")

SELECT prikey, sum(valuea) as valuea, sum(valueb) as valueb;
        from table1 ;
    order by prikey ;
    group by prikey ;
    where between(thedate,startdate,enddate) ;
    into cursor temp1 nofilter

select * from temp1 ;
    UNION ;
select * from empties ;
    into cursor temp2
	
SELECT prikey, sum(valuea), sum(valueb) ;
    from temp2 ;
    order by prikey ;
    group by prikey ;
    into array aFinal
>I have a Select command similar to the following
>
>      SELECT key, valuea, sun(valueb) from table
>            order by key
>            where between(date,startdate,enddate)
>            into array a
>
>My problem is that I can get 1 to 3 rows in the array depending on the data. What I want is to always get 3 rows with zero for non-existant values. For example assume only key2 has a data. I then want the result like
>
>        key1    0
>        key2   12
>        key3    0
>
>What is the best way of doing this?
Steve Gibson
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform