Lynn Pettis (4/3/2013)
kapil_kk (4/3/2013)
Hi all, I have created a sp in which I want to extract last identity value after doing insertion....But its giving me error that @new_identity parameter is not supplied
Create Procedure [dbo].[BS_StoreAllocation_AddSTNDetails]
@StoreCode int = 1,
@CourierName varchar(30) = 'BLUE Dart',
@CourierNo int = 98765732,
@new_identity int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @STN varchar(20)
INSERT INTO GV_STNDetails
VALUES
(
REPLACE(STR(@StoreCode,4),' ','0'),
@CourierName,
@CourierNo,
GETDATE(),
CONVERT(VARCHAR,LEFT(@CourierName,3)) + '-' + CONVERT(VARCHAR,@CourierNo) + CONVERT(VARCHAR(10),GETDATE(),112)
)
SELECT @new_identity = SCOPE_IDENTITY()
RETURN
END
Is this how you are invoking your procedure?
declare @NewValue int; -- will have the value returned by @new_identity
exec dbo.BS_StoreAllocation_AddSTNDetails
@StoreCode = <someinput>,
@CourierName = <someinput>,
@CourierNo = <someinput>,
@new_identity = @NewValue OUTPUT;
Thanks, Lyan
I was invoking the procedure in the wrong way
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/