Im trying to write a procedure to update two tables but im a little stuck on the syntax.
The tables are named SupportTicketsTbl and tblSupportEvent, the link between these tables is a third table named tblTicketsInEvents.
tblSupportEvent has a list of all events that are in a persons schedule, each event has a start and end time, this procedure runs as a sql job and checks if the current time is greater than an events end time, and if so it updates its status.
Now the syntax for this is easy:
UPDATE
tblSupportEvent
SET
[status] = 3
WHERE
eventend < CURRENT_TIMESTAMP
AND
[status] = 1
Now here is my problem, an event is linked to a ticket, so when the event linked to the ticket expires I want to set the tickets assigned to value back to 0.
This SELECT query shows the relationship between the tables:
SELECT
*
FROM
tblSupportEvent e
JOIN
tblTicketsInEvents tie
ON
e.id = tie.eventID
JOIN
SupportTicketsTbl t
ON
t.TicketID = tie.ticketID
The way I can think to solve this is to select all expired ticket ids into a table then to do an update on SupportTicketsTbl where the ticket ID is in my table variable, though this seems a bit messy. Is there a better way of doing this with an update statement / joins etc?
Im asking because although I can solve the problem myself, and it would probably perform fast enough id like to know the right way of doing this.
Thanks
I believe that doing it this way will work better than creating a temporary table.