It will be necessary to do one of two things, in addition to the SEF changes to the script:
1) If the request from the client is for an old dynamic URL, use RewriteMap in httpd.conf (or conf.d) to call a script to take the old dynamic URL, access the database, and retrieve the new static URL. Then generate a 301-Moved Permanently redirect to the new static URL.
2) If the request from the client is for an old dynamic URL, use mod_rewrite in httpd.conf, conf.d, or .htaccess to call a script that accesses the database, retrieves the new static URL, and then generates a 301-Moved Permanently redirect to the new static URL.
Either way will work. What is critical is that 'infinite' rewrite/redirection loops must be avoided. The way to do this is to use RewriteCond examining the server variable THE_REQUEST to be sure that requests for old dynamic URLs are coming direct from the client, and are not being requested as a result of the internal rewriting of the new static URLs.
In other words, the process looks like this:
1) Script puts new static links on the page.
2) Client requests a new static URL as the result of a click on one of these static links on the page.
3) Mod_rewrite or AcceptPathInfo is used to deliver this request to your script.
4) Script produces next page.
5) If a request for an old dyamic URL is received from client, redirect to the new static URL. This must be done without creating a loop due to interaction with step 3.