Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Certain Records 1

Status
Not open for further replies.

TheRambler

Programmer
Jan 23, 2003
523
BO
My data looks like this:
[tt]
Client Jan Feb Mar Apr Jun Jul Aug

A 77 71 106 99 94 118 135
B 0 0 0 25 45 13 25
C 25 80 55 128 0 0 0[blue]
D 217 0 0 301 228 0 0
E 227 86 0 0 0 0 35
F 0 0 15 67 0 0 29[/blue][/tt]

Monthly values can be either zero or positive, I need to retrieve (or just identify with a deletion mark) those records in blue, where zeroes are between positive values. How can I do that?

Here is the sample data:
Code:
CREATE CURSOR sample (client c(1), jan n(3), feb n(3), mar n(3), apr n(3), jun n(3), jul n(3), aug n(3))
INSERT INTO sample VALUES ("A",77,71,106,99,94,118,135)
INSERT INTO sample VALUES ("B",0,0,0,25,45,13,25)
INSERT INTO sample VALUES ("C",25,80,55,128,0,0,0)
INSERT INTO sample VALUES ("D",217,0,0,301,228,0,0)
INSERT INTO sample VALUES ("E",227,86,0,0,0,0,35)
INSERT INTO sample VALUES ("F",0,0,15,67,0,0,29)

I am using VFP7, any ideas are welcome.
 
This code is pretty cumbersome, but I think it'll work.

FUNCTION zero
* locate first non-zero field
fc = FCOUNT()
FOR i = 2 TO fc
IF EVAL(FIELD(i)) > 0
EXIT
ENDIF
ENDFOR
IF i >= fc -1
RETURN 'no'
ENDIF
* locate zero field
FOR j = i + 1 TO fc
IF EVAL(FIELD(j)) = 0
EXIT
ENDIF
ENDFOR
IF j > fc -1
RETURN 'no'
ENDIF
* locate next non-zero field
FOR k = j + 1 TO fc
IF EVAL(FIELD(k)) > 0
EXIT
ENDIF
ENDFOR
IF k > fc
RETURN 'no'
ENDIF
RETURN 'yes'


Jim
 
Hi Jim,

Wow, thanks for your quick reply. Yes, it works! I will try it with the real data right away.

I was thinking of another approach, I thought of converting the numbers into strings like:
[tt]
Client Jan Feb Mar Apr Jun Jul Aug
A 7 71 106 99 94 118 135 = 1111111
B 0 0 0 25 45 13 25 = 0001111
C 25 80 55 128 0 0 0 = 1111000
D 217 0 0 301 228 0 0 = 1001100
E 227 86 0 0 0 0 35 = 1100001
F 0 0 15 67 0 0 29 = 0011001
[/tt]
and then removing leading and trailing zeroes, so that I would get:

1111111
1111
1111
10011
1100001
11001

The rest would be a matter of comparing the length of the string with the sum of 1's, but I won't need to do that now. A starr for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top