all groups > sql server programming > july 2004 >
You're in the

sql server programming

group:

Getting record identity


Getting record identity Larry Bird
7/11/2004 10:57:02 PM
sql server programming:
I am trying to retrieve the identity of a previous inserted record. I’m using the Scope_Identity in my stored procecedure as follows:

CREATE PROCEDURE dbo.InsertEventCriteria @VehicleMinNum char(10), @AlertCategory char, @ReportingFrequency int, @ConfirmRFStartDate char(10), @ConfirmRFStartTime char(8), @ConfirmRFEndDate char(10),
@ConfirmRFEndTime char(8), @SageQuestDateTime datetime, @ConfirmTimeFactorBeginTime char(8), @ConfirmTimeFactorEndTime char(8), @DBMonday char, @DBTuesday char, @DBWednesday char,
@DBThursday char, @DBFriday char, @DBSaturday char, @DBSunday char, @ConfirmEmailAddresses char(200), @CriteriaDisposition char
AS Insert into EventCriteria(Min_Num, EventType,ReportingFrequency, TimeToLiveStartDate, TimeToLiveStartTime, TimeToLiveStopDate, TimeToLiveStopTime, DateTimeStamp, BeginTime, EndTime, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday, Sunday, EmailAddresses, DispositionDisplay )
Values (@VehicleMinNum, @AlertCategory, @ReportingFrequency, @ConfirmRFStartDate, @ConfirmRFStartTime, @ConfirmRFEndDate, @ConfirmRFEndTime, @SageQuestDateTime, @ConfirmTimeFactorBeginTime, @ConfirmTimeFactorEndTime,
@DBMonday, @DBTuesday, @DBWednesday, @DBThursday, @DBFriday, @DBSaturday, @DBSunday, @ConfirmEmailAddresses, @CriteriaDisposition)

SELECT SCOPE_IDENTITY() AS 'CriteriaID'
GO

When I execute the stored procedure above I use the record set ordinal number to retrieve the return record as follows:

Set Alertrs = AlertCMD.Execute

TempCriteriaID = Alertrs(0)

The stored procedure runs well because data is being added to the table. I’m just not getting the identity of the inserted record.

I get the following error message:

Runtime error: 3265

The item cannot be found in the collection corresponding the requested name or ordinal number.

What I’m I doing wrong here?
Re: Getting record identity Larry Bird
7/11/2004 11:51:01 PM
I tired your suggestion using "Set NoCOUNT On". This did not change the results at all. Why might the record set be empty? I'm doing a "Select SCOPE_Identity()" Should there me more code in the stored procedure to return the identity?


[quoted text, click to view]
Re: Getting record identity Larry Bird
7/12/2004 3:54:04 AM
I was not awhere that I was missing the output command to get the identity. Is that my problem? What does the output command look like? I'll also do some research using the online books. Any input you may have is greatly appreicated.

Thanks




[quoted text, click to view]
Re: Getting record identity Aaron [SQL Server MVP]
7/12/2004 7:41:47 AM
[quoted text, click to view]

Add SET NOCOUNT ON to the proc. And instead of using a command object, try
using:

Set Alertrs = connection.object.Execute("EXEC dbo.InsertEventCriteria
@vehicleMinNum = 'blah blah', @alertCategory = 'blah blah', ...")

Or, use an output variable instead of a resultset, which is more efficient
for single scalar values. You can find examples here:
http://www.aspfaq.com/params.htm

--
http://www.aspfaq.com/
(Reverse address to reply.)

Re: Getting record identity Uri Dimant
7/12/2004 9:57:05 AM
Larry
If I understand properly,you are missing OUTPUT command to get out a value
of SCOPE IDENTITY

You can more examples in the BOL




[quoted text, click to view]
results at all. Why might the record set be empty? I'm doing a "Select
SCOPE_Identity()" Should there me more code in the stored procedure to
return the identity?
[quoted text, click to view]

Re: Getting record identity Roji. P. Thomas
7/12/2004 11:47:25 AM
Try adding SET NOCOUNT ON

--
Roji. P. Thomas
SQL Server Programmer
[quoted text, click to view]
@AlertCategory char, @ReportingFrequency int, @ConfirmRFStartDate char(10),
@ConfirmRFStartTime char(8), @ConfirmRFEndDate char(10),
[quoted text, click to view]
@ConfirmRFEndTime char(8), @SageQuestDateTime datetime,
@ConfirmTimeFactorBeginTime char(8), @ConfirmTimeFactorEndTime char(8),
@DBMonday char, @DBTuesday char, @DBWednesday char,
[quoted text, click to view]
@DBThursday char, @DBFriday char, @DBSaturday char, @DBSunday char,
@ConfirmEmailAddresses char(200), @CriteriaDisposition char
[quoted text, click to view]
TimeToLiveStartDate, TimeToLiveStartTime, TimeToLiveStopDate,
TimeToLiveStopTime, DateTimeStamp, BeginTime, EndTime, Monday, Tuesday,
Wednesday, Thursday, Friday,
[quoted text, click to view]
@ConfirmRFStartDate, @ConfirmRFStartTime, @ConfirmRFEndDate,
@ConfirmRFEndTime, @SageQuestDateTime, @ConfirmTimeFactorBeginTime,
@ConfirmTimeFactorEndTime,
[quoted text, click to view]

AddThis Social Bookmark Button