Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select statement returns all records
Message
 
To
16/03/2001 07:46:13
Sammy Derban
Ghana Telecom
Accra, Ghana
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00485792
Message ID:
00485822
Views:
8
>Hello all,
>My 'Select' statement returns all records when the key field is blank ie ""
>The table key field is character. set Exact is on. Vfp 5
>Any help?
>
>Samlpe code:
>SELECT RES_CODE, RES_NAME, RUNIT_CODE FROM RES_REC INTO ARRAY RECARRAY ;
>WHERE rec_no = alltrim(thisform.txtrecno.value)

A value of "" matches all records. It is not a bug. It basically states find all records where the rec_no starts with "". And all records start with nothings.

If you wish to search on only those fields that the user enters data in, then I would build a where clause using a CASE or IF statement.
lcWhere = ''
llAndFlag = .F.
IF NOT EMPTY(thisform.txtrecno.value)
  lcWhere = 'rec_no = ' + alltrim(thisform.txtrecno.value)
  llAndFlag = .T.
ENDIF
IF NOT EMPTY(some.other.field.value)
  IF llAndFlag
    lcWhere = 'AND some_other_field = ' + alltrim(some.other.field.value)
  ELSE
    llAndFlag = .T.
    lcWhere = 'some_other_field = ' + alltrim(some.other.field.value)
  ENDIF
ENDIF
Etc...
HTH
Bret Hobbs

"We'd have been called juvenile delinquents only our neighborhood couldn't afford a sociologist." Bob Hope
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform