LOCATE/LOAD A CASE BY ID VARIABLE IN MIDDLE OF ID VARIABLES

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
emdisala
Posts: 26
Joined: March 16th, 2021, 12:30 pm

LOCATE/LOAD A CASE BY ID VARIABLE IN MIDDLE OF ID VARIABLES

Post by emdisala »

Dear all,

LOCATE/LOAD A CASE BY ID VARIABLE IN MIDDLE OF ID VARIABLES

Suppose we have ID1, ID2 and ID3, ..., IDNN in database

Locate function allows query with PREFIX

Documentation clearly says to use prefix
locate(dictionary_name, relational_operator, key_prefix)

If there is a way to query using second id or next ids giving a wildcard or something similar (??55)
(This operation could archive using forcase statement, but I interest to use locate and loadcase if there is a way)

Code: Select all

if locate(SURVEY_DICT, >=, "??55") then
     do while loadcase(SURVEY_DICT) and ID2 = 55
        // process all cases in ID2 55
     enddo;
endif;
Thank you

Disala
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: LOCATE/LOAD A CASE BY ID VARIABLE IN MIDDLE OF ID VARIABLES

Post by Gregory Martin »

There is no way to do this directly with CSPro logic commands. If you really need to optimize your code, however, you can query the data file's index and use SQLite commands to get a list of applicable keys. For example, if your data file is a CSPro DB file, you could do this:
list string keys_with_55;

sqlquery(SURVEY_DICT, keys_with_55, "SELECT `key` FROM `cases` WHERE INSTR(`key`, '55') = 3;");

do numeric key_counter = 1 while key_counter <= keys_with_55.length()

   
locate(SURVEY_DICT, =, keys_with_55(key_counter));
   
retrieve(SURVEY_DICT);

    // process case

enddo;
You could use the ORDER BY SQLite command if you want to process the cases in a certain order.
emdisala
Posts: 26
Joined: March 16th, 2021, 12:30 pm

Re: LOCATE/LOAD A CASE BY ID VARIABLE IN MIDDLE OF ID VARIABLES

Post by emdisala »

Thank you very much for the information Gregory

Disala
Post Reply