Hey. I am trying to write several case statements to set the priority of a job. There are several tables and identifiers that participate in this, but basically I want to check if the work exists, if it exists, if the question related to it is 80, and then has several status elements, so if the junior category of tasks is 1, The answer will be the identifier for High. The code I have done so far can explain better ...
ALTER Procedure [dbo].[usp_CreatePresetPriority] @HelpdeskID int, @MinorCategoryID int As BEGIN IF EXISTS(SELECT * FROM TicketInformation WHERE TicketID = @HelpdeskID AND QuestionID = 80) BEGIN UPDATE TicketInformation SET AnswerInput = Null, AnswerID = CASE @MinorCategoryID WHEN 87 THEN 129 END WHERE TicketID = @HelpdeskID And QuestionID = 80 END ELSE BEGIN INSERT INTO TicketInformation (TicketID, QuestionID, AnswerID, AnswerInput) VALUES (@HelpdeskID, 80, CASE @MinorCategoryID WHEN 87 THEN 129 END, Null) END
So this works, but only for one option - where @MinorCategoryID = 87 I want to have more than 1 statement that sets @MinorCategoryID WHEN 91THEN 130, etc.
I tried...
IF EXISTS(SELECT * FROM TicketInformation WHERE TicketID = @HelpdeskID AND QuestionID = 80) UPDATE TicketInformation SET AnswerInput = Null, AnswerID = CASE @MinorCategoryID WHEN 87 THEN 129 WHERE TicketID = @HelpdeskID And QuestionID = 80 ELSE INSERT INTO TicketInformation (TicketID, QuestionID, AnswerID, AnswerInput) VALUES (@HelpdeskID, 80, CASE @MinorCategoryID WHEN 87 THEN 129 END, Null) IF EXISTS(SELECT * FROM TicketInformation WHERE TicketID = @HelpdeskID AND QuestionID = 80) UPDATE TicketInformation SET AnswerInput = Null, AnswerID = CASE @MinorCategoryID WHEN 91 THEN 130 WHERE TicketID = @HelpdeskID And QuestionID = 80 ELSE INSERT INTO TicketInformation (TicketID, QuestionID, AnswerID, AnswerInput) VALUES (@HelpdeskID, 80, CASE @MinorCategoryID WHEN 91 THEN 130 END, Null)
Any help is appreciated - sorry if it is not clear, I have a spotty fuzzy head!