| View previous topic :: View next topic |
| Author |
Message |
Craig Stuntz [TeamB] Guest
|
Posted: Fri Dec 05, 2003 7:09 pm Post subject: Re: Return the identity from a stored procedure |
|
|
Doru Roman wrote:
| Quote: | I have a Stored Procedure that inserts a new record in a table.
How do I retrieve the Indentity value for the last inserted?
Can someone help?
|
It isn't possible to answer this question accurately unless you
mention which DB server you're using.
-Craig
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html
|
|
| Back to top |
|
 |
Doru Roman Guest
|
Posted: Fri Dec 05, 2003 8:05 pm Post subject: Return the identity from a stored procedure |
|
|
Hi,
I have a Stored Procedure that inserts a new record in a table.
How do I retrieve the Indentity value for the last inserted?
Can someone help?
--
Thank you,
Doru
|
|
| Back to top |
|
 |
Ray Marron Guest
|
Posted: Fri Dec 05, 2003 8:09 pm Post subject: Re: Return the identity from a stored procedure |
|
|
"Doru Roman" <doruroman (AT) rogers (DOT) com> wrote
....
| Quote: | I have a Stored Procedure that inserts a new record in a table.
How do I retrieve the Indentity value for the last inserted?
Can someone help?
|
Which SQL server? Do you have the ability to modify the procedure?
--
Ray Marron
|
|
| Back to top |
|
 |
Doru Roman Guest
|
Posted: Fri Dec 05, 2003 8:10 pm Post subject: Re: Return the identity from a stored procedure |
|
|
It is SQL 2000
--
Thank you,
Doru
"Craig Stuntz [TeamB]" <cstuntz (AT) nospam (DOT) please [a.k.a. vertexsoftware.com]>
wrote in message news:3fd0e5de$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Doru Roman wrote:
I have a Stored Procedure that inserts a new record in a table.
How do I retrieve the Indentity value for the last inserted?
Can someone help?
It isn't possible to answer this question accurately unless you
mention which DB server you're using.
-Craig
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html
|
|
|
| Back to top |
|
 |
Doru Roman Guest
|
Posted: Fri Dec 05, 2003 8:29 pm Post subject: Re: Return the identity from a stored procedure |
|
|
It's my SP on a SQL 2000 DB, so I can do everything.
I also do not know how to write Delphi code to retrieve it.
I tried:
Insert Into Table(a) Values('a')
Select @@Identity
But what do I do to get the value in my application if the above is correct?
--
Thank you,
Doru
"Ray Marron" <marron+delphi (AT) cableaz (DOT) com> wrote
| Quote: | "Doru Roman" <doruroman (AT) rogers (DOT) com> wrote in message
news:3fd0e4f7$1 (AT) newsgroups (DOT) borland.com...
...
I have a Stored Procedure that inserts a new record in a table.
How do I retrieve the Indentity value for the last inserted?
Can someone help?
Which SQL server? Do you have the ability to modify the procedure?
--
Ray Marron
|
|
|
| Back to top |
|
 |
Kevin Frevert Guest
|
Posted: Fri Dec 05, 2003 8:45 pm Post subject: Re: Return the identity from a stored procedure |
|
|
Doru,
What data-access components are you using? I'll try to provide an
example.
krf
"Doru Roman" <doruroman (AT) rogers (DOT) com> wrote
| Quote: | It's my SP on a SQL 2000 DB, so I can do everything.
I also do not know how to write Delphi code to retrieve it.
I tried:
Insert Into Table(a) Values('a')
Select @@Identity
But what do I do to get the value in my application if the above is
correct? |
|
|
| Back to top |
|
 |
Brian Hollister Guest
|
Posted: Fri Dec 05, 2003 9:05 pm Post subject: Re: Return the identity from a stored procedure |
|
|
Use Output parameters to return the Identity value
create proc TestProc(
@param1 int,
@paramOut int OUTPUT)
as
Insert Into Table(a) Values(@param1)
Select @paramOut = @@Identity
|
|
| Back to top |
|
 |
Doru Roman Guest
|
Posted: Fri Dec 05, 2003 9:10 pm Post subject: Re: Return the identity from a stored procedure |
|
|
It is TADOStoredProc.
And how should the Stored Procedure look like?
--
Thank you,
Doru
|
|
| Back to top |
|
 |
Doru Roman Guest
|
Posted: Fri Dec 05, 2003 9:13 pm Post subject: Re: Return the identity from a stored procedure |
|
|
I tried this too, but what method should I use for the TADOStoredProc
to get the value? OPEN does not work with an INSERT.
EXECPROC does not return the value.
--
Thank you,
Doru
|
|
| Back to top |
|
 |
Kevin Frevert Guest
|
Posted: Fri Dec 05, 2003 9:21 pm Post subject: Re: Return the identity from a stored procedure |
|
|
What I would do..(this is off the top of my head, so there are probably
syntax errors)
CREATE Procedure dbo.proc_InsertData (@Value varchar(30)) AS
declare @NextID int
SET NOCOUNT ON /* Suppressed the " Rows affected" message */
Insert INTO SomeTable
(SomeValue)
Values
(@Value)
Select @NextID = @@Identity
Return @NextID
/* end of stored proc */
In Delphi...I've posted an example in the .attachments folder.
Good luck,
krf
"Doru Roman" <doruroman (AT) rogers (DOT) com> wrote
| Quote: | It is TADOStoredProc.
And how should the Stored Procedure look like?
--
Thank you,
Doru
|
|
|
| Back to top |
|
 |
Doru Roman Guest
|
Posted: Fri Dec 05, 2003 9:35 pm Post subject: Re: Return the identity from a stored procedure |
|
|
Great, it works.
Thank a lot,
Doru
|
|
| Back to top |
|
 |
|