how to retrieve data from database and compare it if there is a match using IF ELSE. VFP 9

StackOverflow https://stackoverflow.com/questions/21950314

  •  15-10-2022
  •  | 
  •  

Question

how to compare if the data is already exists in database in foxpro 9. IF(if found) employee already exist. ELSE insert employee into database.

No correct solution

OTHER TIPS

Your question is too vague on "already exists". What if you are looking for an employee "John Smith" and coincidentally you are a large organization where there are SEVERAL "John Smith" names employed... Do you have other criteria? Such as a social security number, date of birth info, etc? If so, you could run a query something like.

lookForSSN = "123-45-6789"
use in select( "C_IsOnFile" )
select SomeIDColumn ;
   from YourEmployeeTable ;
   where SocSecNum = lookForSSN;
   into cursor C_IsOnFile

if reccount( "C_IsOnFile" ) = 1
   */ Already on file, you can update it
   update YourEmployeeTable;
      set FirstName = FirstNameVar,;
          LastName = LastNameVar,;
          DoB = DoBVar,;
          etc = etcVar;
      where ;
         SSN = lookForSSN
else 
   */ Not on file, add it
   insert into YourEmployeeTable ;
      ( FirstName, LastName, DoB, SSN, etc );
      values;
      ( FirstNameVar, LastNameVar, DoBVar, lookForSSN, etcVar )

endif
*/ close temp cursor when finished
use in select( "C_IsOnFile" ) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top