Friday, June 29, 2012

New flavor to execute query from coldfusion cfscript.


As you know that coldfusion added java coding style in cfscript tag.

Here one example of executing query from coldfusion cfscript tag.

Retrieve resultset with multiple id's

function getResultSetByIDs(string dsn, required numeric userIDs) {
     // Setup a variable for the Query Result
    var qResult = '';
    // Setup the Query variable
    var q= new query();
    // Add Parameter
    q.addParam(name="ID", value=arguments.userIDs, cfsqltype="CF_SQL_INTEGER" list="true");
    // Create the SQL String
    var sqlString="
            SELECT    *
            FROM      USERS
            WHERE    
                      USERID IN (:ID)
        ";
    q.setdatasource(arguments.pDsn);
    q.setsql(sqlString);
    qResult=q.execute().getresult();
    return qResult; 
}

No comments:

Post a Comment