I have a master table "Repairs" and a detail table "RepairDetails" I am trying to write a procedure to update both tables when I send the appropriate parameters from my application. Here is my SQL:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[UpdateRepair]
@RepairID bigint,
@TypeID bigint = NULL,
@Directions nvarchar(3000) = NULL,
@NewDetails NewDetails READONLY
AS
BEGIN
SET NOCOUNT ON;
UPDATE Repairs
SET
TypeID = ISNULL(@TypeID, TypeID),
Directions = ISNULL(@Directions, Directions),
LastUpdate = SYSDATETIME()
WHERE RepairID = @RepairID;
IF @NewDetails IS NOT NULL UpdateRepairDetails;
END
where "NewDetails" is a User-defined table type and "UpdateRepairDetails" is a different stored procedure that takes @RepairID and @NewDetails as parameters.
I have an error and a question. The error message is:
Must declare the scalar variable "@NewDetails"
which I don't understand because it is defined.
And my question is: will the parameters "@RepairID" and "@NewDetails" get automatically passed to the "UpdateRepairDetails" procedure. If not, what is the proper approach to accomplish this?