I'm using SQL2008 R2. I am executing the following query from VS2010.
Code:
USE [MT]
GO
/****** Object:  StoredProcedure [dbo].[POToSparts]    Script Date: 01/19/2016 15:12:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO

 

ALTER PROC [dbo].[POToSparts]

(
@Component Varchar(150),

@QtyonHand numeric,

@EquipmentID Integer,

@VendorID Integer,

@PartNum VarChar(150),

@Price decimal,

@ordqty decimal,

@CompID Integer = NULL OUTPUT
)

AS

BEGIN

SET NOCOUNT ON;

/*DECLARE @CompID INT*/

INSERT INTO sparts

                      (Component, Priority, QtyonHand, PointofReorder, OrderedAmnt, Status)

VALUES     (@Component, '3',@QtyonHand, '0', @ordqty, 'Active');

SET @CompID = SCOPE_IDENTITY()

INSERT INTO compequip (ComponentID, EquipmentID ) VALUES (@CompID, @EquipmentID)

INSERT INTO spartven (ComponentID , Component, VendorID , PartNum , Price, PrimaryVendor) VALUES (@CompID, @Component, @VendorID, @PartNum, @Price, 'True')

SELECT SCOPE_IDENTITY ()

END
It is returning two different values. Where is it getting that first value of 4050. The value I'm expecting is the 3411. I fear I am not understanding something here.
Name:  Scope_Identity.JPG
Views: 724
Size:  47.1 KB

Thanks,
Stacy