Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get the current value from a transactional table
Message
From
24/09/2001 15:34:26
 
 
To
24/09/2001 12:10:33
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00560054
Message ID:
00560159
Views:
18
Hi,Sorin

Person DATE CODE VALUE
001 1/1/2000 C001 123.00
001 1/5/2000 C002 5.00
001 1/10/2000 C001 50.00
001 1/15/2000 C002 10.00
002 1/2/2000 C001 12.00
002 1/6/2000 C002 52.00
002 1/11/2000 C001 51.00
002 1/14/2000 C002 13.00

all persons all codes when a date is provided?
one person all codes when a date is provided?
all person one codes when a date is provided?
one person one codes when a date is provided?
&& parms or condition would be empty or not empty
&& if you want all person or one person. 

lcPerson='person code'
lcCode='somecode'

lcPerson=IIF(!EMPTY(lcPerson),"person="+"'"+lcPerson+"'",'')
lcCode=IIF(!EMPTY(lcCode),"code="+"'"+lcCode+"'",'')
lcCond=IIF(!EMPTY(lcPerson),' and '+lcPerson,'')+ ;
       IIF(!EMPTY(lcCode),' and '+lcCode,'') 

&& date conditon
lcWhere='where date < somedate '+lcCond

&& supposed table has index tag of person/code/date

&& first, querys records within criteria..
&& and orders them by person/code/date..

lcSource=SYS(2015)
select * from (mycursor) ;
   &lcWhere ;
    group by person,code into (lcSource) NOFILTER order by person,code,date

&& collect max.date's record per person/code
&& 'group by' automatically takes last record.

lcTarget=SYS(2015)
select person,date,code,value ;
     from (lcTarget) ;
          group by person,code into (lcTarget) order by person,code

&& Hacker's Guide says..this kind of query is not reliable..
&& I've tried many times in similar situation like you but  
&& didn't find a problem by now.
&& But I don't take this method for not-large data, would rather
&& use 'set key to' after proper indexing.
&& Someone's advice would be appreciated.
Just my Thoughts.

RGDS
HK.Lee
MCP
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform