Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Aways get a 3x3 array from a SQlL select command
Message
De
14/05/2003 10:58:00
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
14/05/2003 10:48:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00788138
Message ID:
00788193
Vues:
20
Claude,
SQL would return a sum() either 0 or more for a key. However it's 'where' clause filtering the data so for a specific key if no transaction occured then there is no data for it (not sum). So you might tweak the SQL a bit so you'd always get all the keys :
SELECT key, ;
  sum(iif(between(date,startdate,enddate),1,0)*valuea), ;
  sum(iif(between(date,startdate,enddate),1,0)*valueb) ;
  from table ;
  group by key ;
  order by key ;
  into array arrResult
Cetin

>Sorry I had a typo it shuld have been
>
>   SELECT key, sum(valuea), sun(valueb) from table
>        order by key
>        where between(date,startdate,enddate)
>        into array a
>
>where key are 3 specific stock codes and valuea and valueb are number of items recieved originally and from back orders on specific dates. So what I am trying to get is number of items recieved for each stock code in a give date range. For some some date ranges nothing may have been recieved. SQL select only returns a row when sums are non-zero. So if on key2 has recieved any items in a date range then only 1 row is returned. What I need is an array to has 3 rows and zeros for keys values where nothing is recieed. The best I could think of is to create the a 3x3 matrix with 3 key fields in column1 and zeros for columns 2 and 3 and then add non-zero values to appropriate cells. My question s are:
>
>1. Is this a reasonable approach? If so what is the best method of doing this?
>2. Is there a better method? If so what is it?
>

>
>>>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?
>>
>>
>>dimension arrRet[3,2]
>>arrRet = 0
>>for ix=1 to 3
>> arrRet[ix,1] = 'key'+trans(ix)
>>endfor
>>      SELECT key, valuea, sun(valueb) from table ;
>>            order by key ;
>>            where date between startdate and enddate ;
>>            into array arrRet && No grouping - is it sun() or sum() ?
>>
>>PS: Tweak names.
>>
>>Update: Forget about above code. Reread your question. What does valuea stand for (thinking it's sum())
>>Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform