I have a few table's in my DB.
I am trying to update the rota table using a SQL stored procedure. I want the user to be able to type in, for example;
Name: Adam Brookes
Shift: Middle Day
On Call: Secondary
and using a subquery have it look up the id's of those and place them into the rota table. At the moment I am testing in Postman where I can define the 'date' and 'datekey' manually.
My Stored Procedure currently looks like this;
ALTER PROCEDURE [dbo].[RotaUpdateItems]
@date_key int,
@date date,
@user_id varchar(max),
@shift_type_id int,
@type_call_id int
AS
BEGIN
SET NOCOUNT ON;
UPDATE rota
SET date = @date,
user_id = (
SELECT user_id
FROM staff s
WHERE s.first_name LIKE 'ABC%'
),
shift_type_id = (
SELECT shift_type_id
FROM shifts h
WHERE h.shift_type LIKE 'ABC%'
),
type_call_id = (
SELECT type_call_id
FROM on_call c
WHERE c.type_of_call LIKE 'ABC%')
WHERE date_key = @date_key
END
I have referenced this question to get the LIKE 'ABC%' code to see if that would help convert "Primary" into '1', but this did not fully answer my question
I also researched this answer from John to see if a join is necessary when running an update query but this did not fully answer my question.