Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:58:14+00:00 2026-05-27T04:58:14+00:00

Im trying to write a procedure to update two tables but im a little

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:58:14+00:00Added an answer on May 27, 2026 at 4:58 am

    I believe that doing it this way will work better than creating a temporary table.

    UPDATE SupportTicketsTbl
    SET toUpdate = newVal
    WHERE
        ticketID IN (
            SELECT id
            FROM tblSupportEvent
            WHERE expiredCondition
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of a syntax question I'm trying to write a store procedure
I am trying to write a store procedure in phpmyadmin but I get this
I am trying to write a trigger but getting syntax error: CREATE TRIGGER archive_domain_trig
I'm trying to write a stored procedure that will return two calculated values for
I am new stored procedures and trying to write a procedure to duplicate user(by
I'm trying to write a stored procedure to select employees who have birthdays that
I am trying to write a stored procedure which selects columns from a table
I'm trying to write a stored procedure that will read an Excel file into
I'm trying to write a stored procedure in SQL that will : Make a
In MySQL I'm trying to write a Stored Procedure which does the following: Run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.