sql server - SQL ID from table posts same ID to all other coldfusion entries per transaction -
how trigger id transaction table same on entries each table per session? trying insert lot of information many tables trying keep tables linked transactionid , struggling on how creates transactionid first entry grabbing entry , using on other table entries.
(this insert create transaction. should automatically create id in transaction table since id primary key in transaction table , isidentity yes , increment of one)
<cfquery datasource="titlesbymail" name="insertentry"> insert dbo.transaction (type, ownertype) values ( <cfqueryparam value='nonleased' cfsqltype='cf_sql_varchar' /> , <cfqueryparam value='owner' cfsqltype='cf_sql_varchar' /> ) </cfquery>
this creates transaction table:
id: 1
type: nonleased
ownertype: owner
i trying figure out how can keep same transaction id inserted next entries other 6 tables (if table exists)
<cfquery datasource="titlesbymail" name="customerinsertentry"> insert dbo.customer (transactionid, id, firstname, lastname) values ( <cfqueryparam value= **'(id transaction table)'** cfsqltype='cf_sql_int' /> , <cfqueryparam value='1' cfsqltype='cf_sql_int' /> , <cfqueryparam value='#session.checkout.info.firstname_1#' cfsqltype='cf_sql_varchar' /> , <cfqueryparam value='#session.checkout.info.lastname_1#' cfsqltype='cf_sql_varchar' /> ) </cfquery>
this new me , have done lots of research keep coming across sql commands of triggers , have no idea how applies coldfusion set this.
when using cfquery
can use results attribute return information based on query run. 1 part of information generatedkey
. can assign generatedkey
variable , use later in code.
so first need add result attribute first cfquery
.
<cfquery datasource="titlesbymail" name="insertentry" result="transactionresult"> insert dbo.transaction (type, ownertype) values ( <cfqueryparam value='nonleased' cfsqltype='cf_sql_varchar' /> , <cfqueryparam value='owner' cfsqltype='cf_sql_varchar' /> ) </cfquery>
then assign variable use generatedkey
result (or use result variable directly)
i.e. <cfset theid = transactionresult.generatedkey>
then use variable anywhere else in code.
<cfquery datasource="titlesbymail" name="customerinsertentry"> insert dbo.customer (transactionid, id, firstname, lastname) values ( <cfqueryparam value='#theid#' cfsqltype='cf_sql_integer' /> , <cfqueryparam value='1' cfsqltype='cf_sql_integer' /> , <cfqueryparam value='#session.checkout.info.firstname_1#' cfsqltype='cf_sql_varchar' /> , <cfqueryparam value='#session.checkout.info.lastname_1#' cfsqltype='cf_sql_varchar' /> ) </cfquery>
Comments
Post a Comment