I need to create a stored procedure and update sample status depends on sample_status value returned from the system but I got this error when executing the procedure:
Msg 137, Level 15, State 2, Line 14
Must declare the scalar variable "@SAMPLE_STATUS".
This is the stored procedure:
CREATE PROCEDURE [dbo].[UPDATE_SAMPLE_DETAILS_STATUS]
@ORDER_ID int,
@TESTID int,
@SAMPLE_STATUS int
AS
IF (@SAMPLE_STATUS = 1)
BEGIN
UPDATE [Lab_Hematology_Samples_Details]
SET SAMPLE_STATUS = 2
WHERE ORDER_ID = @ORDER_ID
AND testid = @testid
END
ELSE IF (@SAMPLE_STATUS = 2)
BEGIN
UPDATE [Lab_Hematology_Samples_Details]
SET SAMPLE_STATUS = 3
WHERE ORDER_ID = @ORDER_ID
AND testid = @testid
END
ELSE IF (@SAMPLE_STATUS = 3)
BEGIN
UPDATE [Lab_Hematology_Samples_Details]
SET SAMPLE_STATUS = 4
WHERE ORDER_ID = @ORDER_ID
AND testid = @testid
END
ELSE IF (@SAMPLE_STATUS = 4)
BEGIN
UPDATE [Lab_Hematology_Samples_Details]
SET SAMPLE_STATUS = 5
WHERE ORDER_ID = @ORDER_ID
AND testid = @testid
END
ELSE IF (@SAMPLE_STATUS = 5)
BEGIN
UPDATE [Lab_Hematology_Samples_Details]
SET SAMPLE_STATUS = 6
WHERE ORDER_ID = @ORDER_ID
AND testid = @testid
END
Where to declare @SAMPLE_STATUS
to solve this error?