home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 11 / CDACTUAL11.iso / cdactual / demobin / share / os2 / VPREVAL / DATAPROC._ / GET_MAX < prev    next >
Encoding:
Text File  |  1994-01-13  |  647 b   |  26 lines

  1. /* obtain next unique record number */
  2. Arg window table_name table_column
  3.  
  4. last_id = 0;
  5.  
  6. prep_string = "SELECT MAX("|| table_column || ") FROM "|| table_name
  7.  
  8. call sqlexec 'DECLARE c9 CURSOR FOR s9';
  9.  
  10. call sqlexec 'PREPARE s9 FROM :prep_string';
  11. if ( SQLCA.SQLCODE <> 0) then
  12.      response=VpMessageBox(window,TITLE,'DB Error with PREPARE STATEMENT.  SQLCODE = 'SQLCA.SQLCODE)
  13. else do
  14.    call sqlexec 'OPEN c9';
  15.  
  16.    do while (SQLCA.SQLCODE = 0)
  17.         call sqlexec 'FETCH c9 INTO :last_id';
  18.         if ( SQLCA.SQLCODE <> 100) then
  19.              last_id = last_id + 1;
  20.    end
  21. end
  22.  
  23. call sqlexec 'CLOSE c9';
  24.  
  25. return last_id
  26.