Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Index problem
Message
From
29/10/2006 05:10:47
 
 
To
29/10/2006 04:12:30
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01165351
Message ID:
01165353
Views:
15
This message has been marked as the solution to the initial question of the thread.
Chaim,

For an index expression, the key must be constant in length

alltrim(str(themonth))
alltrim(str(1)) = '1'
alltrim(str(10)) = '10'

see below

>Hi all
>I created index for year+month and if there is no value for month 1, I get the month 10 value.
>Please take a look on the following code, you get value for 01/2004 from 10/2004:
>
create cursor saled (theyear i, themonth i,units i)
>
>for i=3 to 12
>ii=i+18
>iii=ii*ii
>insert into saled values (2004,i,iii)
>endfor
>
>for i=1 to 12
>ii=i+45
>iii=ii*ii
>insert into saled values (2005,i,iii)
>endfor
>
>
>for i=1 to 12
>ii=i+72
>iii=ii*ii
>insert into saled values (2006,i,iii)
>endfor
>
>
>select saled
>index on alltrim(str(theyear))+alltrim(str(themonth))tag ymd

index on padl(theyear, 4, '0') + padl(themonth, 2, '0') tag ymd


>set order to tag ymd in saled
>
>select distinct themonth from saled  into cursor yearsm readwrite  nofilter
>alter table yearsm add column sl2004 i
>alter table yearsm add column sl2005 i
>alter table yearsm add column sl2006 i
>
>
>select yearsm
>scan
>	cthemonth=alltrim(str(yearsm.themonth))
        cthemonth = padl(yearsm.themonth, 2, '0')

>	cyearm='2004'+cthemonth
>	select saled
>	if seek (cyearm,'saled','ymd')=.f.
>		loop
>	endif
>	replace yearsm.sl2004 with saled .units in yearsm
>endscan
>
>
>
>select yearsm
>scan
>	cthemonth=alltrim(str(yearsm.themonth))
        cthemonth = padl(yearsm.themonth, 2, '0')

>	cyearm='2005'+cthemonth
>	select saled
>	if seek (cyearm,'saled','ymd')=.f.
>		loop
>	endif
>	replace yearsm.sl2005 with saled .units in yearsm
>endscan
>
>
>select yearsm
>scan
>	cthemonth=alltrim(str(yearsm.themonth))
        cthemonth = padl(yearsm.themonth, 2, '0')

>	cyearm='2006'+cthemonth
>	select saled
>	if seek (cyearm,'saled','ymd')=.f.
>		loop
>	endif
>	replace yearsm.sl2006 with saled .units in yearsm
>endscan
>
>
>
>select yearsm
>brow
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform