You can use this inside an stored procedure, for instance:

CREATE PROCEDURE SP_INSERT_TRANSACCION
@transacfecha datetime,
@observacion char(100)
 AS
INSERT INTO Transaccion(transacfecha, observacion)
VALUES(
@transacfecha,
@observacion
)
SELECT @@IDENTITY AS 'nrotrans'
END

In this example, I insert two values with this sp in a table with and
Identity column. So, the SP return the value of the transaccion generated...
You've got the idea???


Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-----Original Message-----
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:36 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This doesn't work as expected through ODBC... it does not seem to return any
value...

<>< Ryan

-----Original Message-----
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:09 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This is from de books online (MSSQL).

@@IDENTITY (T-SQL)
Returns the last-inserted identity value. 

Syntax
@@IDENTITY

Return Types
numeric

Remarks
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

Examples
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.

INSERT INTO jobs (job_desc,min_lvl,max_lvl)

VALUES ('Accountant',12,125)

SELECT @@IDENTITY AS 'Identity'

  

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-----Original Message-----
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


for MS SQL and Oracle does anyone know a more reliable way to do this than
select max(ID) immediately after the insert? It seems silly that I'd have to
take my chances that another has been inserted in between.

<>< Ryan

-----Original Message-----
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
> Hi all,
> 
> How do I do this:
> 
> I need a PHP page that simply creates a "blank" record so that I have the
> record's ID (which is automatically generated).  That same page then needs
> to return the record ID back so that I know what the ID is.  I will later
> allow that record's information to be populated based on the ID it first
> returned.
> 
> How would I do this?
> 
> Thank you, thank you!
> 
> Doug Coning
> 
> 
> 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Email Disclaimer

The information in this email is confidential and may be
legally privileged.
It is intended solely for the addressee.
Access to this email by anyone else is unauthorised.
If you are not the intended recipient, any disclosure,
copying, distribution
or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.
When addressed to our clients any opinions or advice
contained in this email are subject to the terms and
conditions expressed in the governing KPMG client engagement
letter.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to