Inside Out Outside In

Stupid MS Access Tricks

You've probably read that MS Access doesn't support stored procedures.  The real answer that it does, but not as you would expect to use it in ColdFusion.  When you issue a create procedure such as below;

Note: Below code was run on CFMX 7 with the cfbookclub MSAccess db.

<cfquery datasource="cfbookclub" >
CREATE PROCEDURE spByAuthor
AS
SELECT AUTHORS.FIRSTNAME, AUTHORS.LASTNAME, BOOKS.BOOKID, BOOKS.TITLE
FROM AUTHORS INNER JOIN BOOKS ON AUTHORS.AUTHORID=BOOKS.AUTHORID
WHERE AUTHORS.LASTNAME LIKE [@authorlast];
</cfquery>

You end up with a saved query.  With ColdFusion you can call queries in Access just as you would a table.  The problem occurs when the saved query has a parameter.  The standard cfstoredproc tag has a problem calling the stored procedure/query in Access and will result in an error.

The way to call the saved query with a param is as follows;

<cfquery name="qryBooks" datasource="cfbookclub" >
        EXECUTE spByAuthor <cfqueryparam cfsqltype="cf_sql_varchar" value="M%">
</cfquery>

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
zac spitzer's Gravatar nice trick :) just be careful using access for anything (in production) ... it's just asking for trouble..
# Posted By zac spitzer | 11/9/07 1:17 AM
Christopher Wigginton's Gravatar It all depends on the type of site and usage. I've used Access on one site for several years and not a single problem, it just hasn't been worth the effort to rework that site for MSSQL. most of what the site uses it for isn't transactional and it's not ecommerce, so no worries. I lock where I need to and take the necessary small performance hit.\n\nMostly I work in Oracle (preferred) for production along with mySQL and MSSQL. Access is great for non-critical sites or quick and dirties.
# Posted By Christopher Wigginton | 11/9/07 2:55 PM