samedi 25 avril 2015

SQL ID from table posts same ID to all other coldfusion entries per transaction

How do I trigger my ID from my Transaction table to be the same on all entries to each table per session? I am trying to insert a lot of information to many tables but trying to keep all tables linked together by TransactionID and am struggling on how it creates the TransactionID with the first entry then grabbing that entry and using it on all other table entries.

(This is my insert to create the Transaction. This should automatically create an ID in my Transaction table since ID is my primary key in the transaction table and IsIdentity is yes and increment of one)

<cfquery datasource="Titlesbymail" name="InsertEntry">
 INSERT INTO dbo.Transaction (Type, OwnerType)
 VALUES (
    <cfqueryparam value='NonLeased' cfsqltype='cf_sql_varchar' />
   , <cfqueryparam value='Owner' cfsqltype='cf_sql_varchar' />
 )
</cfquery>

This then creates the transaction table:
ID: 1
Type: NonLeased
OwnerType: Owner

I am trying to figure out how I can keep that same transaction ID to be inserted with my next entries to my other 6 Tables (if the table exists)

<cfquery datasource="Titlesbymail" name="CustomerInsertEntry">
 INSERT INTO dbo.Customer (TransactionID, ID, FirstName, LastName)
 VALUES (
    <cfqueryparam value= **'(ID from 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 is completely new to me and have done lots of research I just keep coming across sql commands of triggers and all but have no idea how that applies with my coldfusion set up like this.

Aucun commentaire:

Enregistrer un commentaire