I have written the following stored procedure to retrieve a special list of numbers from an ID Generating table.
I want the out put to be the new ID number... I am trying to pass in the parameter use a sql command object with parameters added.. I am getting back an error message that indicates that a parameter is not being passed in. Can some one help me understand how to make the call?
----------------------------------------------------------------------------
CREATEPROCEDURE csadmin.[uspGetSetDemandPlanMaxID]
-- Add the parameters for the stored procedure here
@OUT_ID INTOUTPUT
AS
BEGIN
BEGINTRY
DECLARE @IN_ID INT
-- interfering with SELECT statements.
--SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT @OUT_ID = i.DMD_PLN_IDFROM csadmin.IDNUM_GEN i
-- demand plan id is what we are trying to get
SELECT @IN_ID =Max(d.DMD_PLN_ID)FROM cspao.DEMAND_PLAN d
-- ------------------------------------------------------------------------
-- -----------------------------------------------------------------------
IF @OUT_ID >= @IN_ID
BEGIN
UPDATE csAdmin.IDNUM_GEN
SET DMD_PLN_ID = @OUT_ID+ 1
SET @OUT_ID = @OUT_ID+1
RETURN @OUT_ID;
END
ELSE
-- --------------------------------------------------------------------
-- Condition #2 - Number From ID Gen is Less than ID from Demand Plan Table
-- In this condition, the numbers have been missed some how and we must
-- adjust them for proper ID alignment to prevent an PK issue.
-- ------------------------------------------------------------------------
BEGIN
IF @OUT_ID < @IN_ID
BEGIN
UPDATE csadmin.IDNUM_GEN
SET DMD_PLN_ID = @IN_ID+ 1
SET @OUT_ID = @IN_ID+1
RETURN @OUT_ID
END
END
ENDTRY
BEGINCATCH
-- THROW 50001,'ID Number could not be updated!', 16;
-- RETURN 16;
--PRINT 'ERROR OCCURED'
ENDCATCH
END