Tuesday, February 24, 2009

SQLExec() ... Small Tips

As we know, SQLExec() returns only a single row of data and if the SQL statement retrieves more than one row of data, SQLExec sends only the first row to its output variables. Any subsequent rows are discarded. So, let's use SQLEXEC() function wisely.
We need to retrieve DEPTID, JOBCODE, from the most effective dated row less than current date, for &emplid=101 ( from PS_JOB). So, one of the easiest way to do that would be:

SQLExec("SELECT DEPTID, JOBCODE FROM PS_JOB WHERE EMPLID=:1 AND EFFDT<=%CurrentDateIn ORDER BY EFFDT DESC, EFFSEQ DESC", &emplid, &empl_dept, &empl_jobcd);
ORDER BY clause can play key role in case of SQLExec() function.
Can we use /*+ FIRST_ROWS */ hint for better performance when we've a complex SQL statement ? Think about it !

No comments:

Post a Comment