Just before your </cfquery> and after the closing parentheses:

)
SELECT SCOPE_IDENTITY()
</cfquery>

-----Original Message-----
From: Robert Makowski [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 01, 2006 10:36 AM
To: CF-Newbie
Subject: RE: inserting into two different tables

I'm using an access db (really small app)

Here is the add function.  I'm unclear where to put the SELECT
SCOPE_IDENTITY()

cfquery name="InsertOwner"
        datasource="#Request.MainDSN#">

        INSERT INTO Owners(
                FIRSTNAME,
                LASTNAME,
                EMAIL,
                STREET,
                UNITNUMBER,
                CTY,
                STATE,
                ZIP,
                PHONE,
                PROJECT,
                NUMBEROFUNITS,
                NOTES
        )
        VALUES (
                '#Trim(Form.firstName)#',
                '#Trim(Form.lastName)#',
                <cfif Len(Trim(Form.emailAddress)) GT 0>
                        '#Trim(Form.emailaddress)#'
                <cfelse>
                        NULL
                </cfif>,
                '#Trim(Form.street)#',
                <cfif Len(Trim(Form.unit)) GT 0>
                        '#Trim(Form.unit)#'
                <cfelse>
                        NULL
                </cfif>,
                '#Trim(Form.city)#',
                '#Trim(Form.state)#',
                '#Trim(Form.zip)#',
                <cfif Len(Trim(Form.phone)) GT 0>
                        '#Trim(Form.phone)#'
                <cfelse>
                        NULL
                </cfif>,
                '#Trim(Form.property)#',
                <cfif Len(Trim(Form.numUnits)) GT 0>
                        '#Trim(Form.numUnits)#'
                <cfelse>
                NULL
                </cfif>,
                <cfif Len(Trim(Form.notes)) GT 0>
                        '#Trim(Form.notes)#'
                <cfelse>
                NULL
                </cfif>
        )

        </cfquery>



The field is call datecontacted which needs to go into a table called
dates.


-----Original Message-----
From: Daniel Kessler [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 01, 2006 11:21 AM
To: CF-Newbie
Subject: Re: inserting into two different tables

What is your database?
If you're using Oracle (and I only really know oracle), you can use:

<CFQUERY NAME="get_id" DATASOURCE="dpch">
     Select my_sequence.NextVal as id From DUAL
</CFQUERY>

and then use the variable ID in each of the two inserts.

Or you can do one insert, query and then do a second insert.  You 
probably should block that within a cftransaction (I think).

On Nov 1, 2006, at 11:03 AM, Robert Makowski wrote:

> I have a fairly basic form that I am submitting.  It's a simple add
> form: first, last name, address, email, etc., but there is a date 
> field
> that I'm putting into another table.  The date table has a bunch of 
> date
> fields, and the foreign key is the ownerid from the other table.  The
> problem is that I'm creating a new owner with a new id, so I can't 
> just
> to two inserts, because I the owenerid hasn't been created yet.  Could
> someone help me with this?
>
>
>
> Thanks.
>
>
>
> Rob Makowski
>
>


--

Daniel Kessler

College of Health and Human Performance
University of Maryland
Suite 2387 Valley Drive
College Park, MD  20742-2611
Phone: 301-405-2545
http://hhp.umd.edu








~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:2183
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to