You're missing a few things.
First of all, you can't invoke @@IDENTITY. It's purpose is to save the identity value of a row you just inserted. Also, it's got issues with scoping, so you should use SCOPE_IDENTITY instead.
Your first procedure needs to return the inserted identity to the outer wrapper. This can be accomplished by using an OUTPUT parameter.
CREATE PROCEDURE dbo.testinsert333
(
@TableID TINYINT
,@OrderID INT OUTPUT
)
AS
BEGIN
INSERT INTO dbo.Orders (Orders.TableID)
VALUES (@TableID)
SET @OrderID = SCOPE_IDENTITY()
END
Your second procedure needs to just accept @OrderID. There's no way for this thread to snag an inserted identity value from a different thread. It must come in as a parameter.
CREATE PROCEDURE dbo.testinsert666
(
@OrderID INT
,@ProductID INT
,@Price INT
,@Quantity SMALLINT
,@OrderStatus BIT
)
AS
BEGIN
INSERT INTO dbo.OrderDetails
(
OrderID
,ProductID
,Price
,Quantity
,OrderStatus
)
SELECT @OrderID
,@ProductID
,@Price
,@Quantity
,@OrderStatus
END
GO
Now to tie all this together, they need to be called together, as in the example below.
BEGIN
DECLARE @OrderID INT
EXEC dbo.testinsert333 @TableID = 1, @OrderID = @OrderID OUTPUT
EXEC dbo.testinsert666
@OrderID = @OrderID
,@ProductID = @ProductID
,@Price = @Price
,@Quantity = @Quantity
,@OrderStatus = @OrderStatus
END
However, the best approach is to nest these two procedures into one, like below.
CREATE dbo.usp_AllInWonder
(
@TableID INT
,@ProductID INT
,@Price INT
,@Quantity SMALLINT
,@OrderStatus BIT
)
AS
BEGIN
DECLARE @OrderID INT
INSERT INTO dbo.Orders (Orders.TableID)
VALUES (@TableID)
SET @OrderID = SCOPE_IDENTITY()
INSERT INTO dbo.OrderDetails
(
OrderID
,ProductID
,Price
,Quantity
,OrderStatus
)
SELECT @OrderID
,@ProductID
,@Price
,@Quantity
,@OrderStatus
END