BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Return the identity from a stored procedure

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Craig Stuntz [TeamB]
Guest





PostPosted: Fri Dec 05, 2003 7:09 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote



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





PostPosted: Fri Dec 05, 2003 8:05 pm    Post subject: Return the identity from a stored procedure Reply with quote



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





PostPosted: Fri Dec 05, 2003 8:09 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote



"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





PostPosted: Fri Dec 05, 2003 8:10 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote

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





PostPosted: Fri Dec 05, 2003 8:29 pm    Post subject: Re: Return the identity from a stored procedure Reply with 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?

--

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





PostPosted: Fri Dec 05, 2003 8:45 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote

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





PostPosted: Fri Dec 05, 2003 9:05 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote

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





PostPosted: Fri Dec 05, 2003 9:10 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote

It is TADOStoredProc.
And how should the Stored Procedure look like?

--

Thank you,
Doru


Back to top
Doru Roman
Guest





PostPosted: Fri Dec 05, 2003 9:13 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote

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





PostPosted: Fri Dec 05, 2003 9:21 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote

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





PostPosted: Fri Dec 05, 2003 9:35 pm    Post subject: Re: Return the identity from a stored procedure Reply with quote

Great, it works.

Thank a lot,
Doru


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.