Try this example
CREATE PROCEDURE MyProc
BEGIN
--Stored Procedure variables
Declare @maxOr int;
Declare @maxCa int;
--Getting query result in the variable (first variant of syntax)
SET @maxOr = (SELECT MAX(orId) FROM [order]);
--Another variant of seting variable from query
SELECT @maxCa=MAX(caId) FROM [cart];
--Updating record through the variable
INSERT INTO [order_cart] (orId,caId)
VALUES(@maxOr, @maxCa);
--return values to the program as dataset
SELECT
@maxOr AS maxOr,
@maxCa AS maxCa
-- return one int value as "return value"
RETURN @maxOr
END
GO
SQL-command to call the stored procedure
EXEC MyProc