I have Insert statement that should return Auto Increment column value. Here is example of my insert:
myQuery = new query();
myQuery.name = "insertRec";
myQuery.setDatasource("db");
mySQL = "
INSERT INTO myTable (
First, Last, Email, ActionDate
)VALUES(
:first, :last, :email, :actiondt
)
";
myQuery.setSQL(mySQL);
myQuery.addParam(name="first", cfsqltype="cf_sql_varchar", value="#trim(form.first)#", maxlength="50");
myQuery.addParam(name="last", cfsqltype="cf_sql_varchar", value="#trim(form.last)#", maxlength="50");
myQuery.addParam(name="email", cfsqltype="cf_sql_varchar", value="#trim(form.email)#", maxlength="320");
myQuery.addParam(name="actiondt", cfsqltype="cf_sql_timestamp", value="#now()#");
myQuery.execute().getResult();
//result = myQuery.execute().getResult(); This line is commented because I was getting error message that test variable is not defined. Not sure why since test is declared and equals to myQuery.execute().getResult();
After I run this code record will appear in the table. Result set looks like this:
RecordID First Last Email ActionDt
7 John Woss jwoss@gmail.com 16-NOV-18
As you can see RecordID
(auto increments) is there. I would like to get that value once myQuery is completed. How to achieve that?