SQL SERVER

<cfquery name="qrySQLInsert" datasource="#variables.cfcDSN#">

SET NOCOUNT ON

            INSERT INTO  table_name (field1,field2,…)

VALUES(value1,value2,…)

            SELECT @@IDENTITY [NewId]

</cfquery>

 

<cfoutput>

New id:  #qrySQLInsert.NewId#

</cfoutput>

 

 

ORACLE

<cfquery name="qryNewID" datasource="#variables.cfcDSN#">

SELECT [sequence].NEXTVAL as numProductID

            FROM DUAL

</cfquery>

<cfset variables.numProductID = qryNewID.numProductID>

 

<cfquery name="qrySQLInsert" datasource="#variables.cfcDSN#">

INSERT INTO  table_name (numProductID,field2,…)

VALUES(#variables.numProductID#,value2,…)

</cfquery>

 

 

 

Thanks

 

Tom Schreck

972-361-9943


From: Jordan Gouger [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 10, 2005 10:31 AM
To: [email protected]
Subject: Re: OT: ORACLE Sequence

 

Really... Wow there so much that I need to learn about SQL server.  I have always retrieved identity by wrapping an insert with a transaction and then selecting the max ID ie SELECT MAX(Identity) AS MaxID in another query.

 

How do you effectivily use the @@Identity property?

 

Thanks,

 

Jordan

"Schreck, Tom" <[EMAIL PROTECTED]> wrote:

Is there a way to query what the next sequence number will be?  In SQL Server, you can use @@Identity to retrieve the newly inserted record’s identity value.  In ORACLE, they use sequences.  I need to know the value of the sequence so I can return it after inserting a record.

 

 

Thanks

 

Tom Schreck

Applications Developer

Dresser, Inc.

15455 Dallas Parkway, Suite 1100

Addison, TX  75001-4690

972-361-9943

[EMAIL PROTECTED]

 

 

 

 

 

 

<<attachment: image001.jpg>>

Reply via email to