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 8616667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:40:40+00:00 2026-06-12T05:40:40+00:00

I have defined the following procedure successfully in my database, but somehow it doesn’t

  • 0

I have defined the following procedure successfully in my database, but somehow it doesn’t work as expected.

CREATE PROCEDURE `mod_prefer`(IN sid INT)
BEGIN
declare s1 int;
declare s2 int;
SELECT SUM(c_load) INTO s1 FROM course WHERE id IN (SELECT course_id FROM prefer WHERE staff_id = sid) AND sem = 1;
SELECT SUM(c_load) INTO s2 FROM course WHERE id IN (SELECT course_id FROM prefer WHERE staff_id = sid) AND sem = 2;
IF s1>s2 THEN
UPDATE staff SET sem = 1 WHERE id = sid;
ELSE
UPDATE staff SET sem = 2 WHERE id = sid;
END IF;
END

The above procedure is called using a trigger as follows (it’s an after insert trigger):

CALL mod_prefer(new.staff_id);

The result is that instead of setting the sem value for the given staff member, the procedures updates all sem values to 2, irrespective of how the logic should work i.e. even if the value for sem should actually be 1.

Please Help.

  • 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-06-12T05:40:41+00:00Added an answer on June 12, 2026 at 5:40 am

    Try this code –

    SELECT
      SUM(IF(sem = 1, c_load, NULL)), SUM(IF(sem = 2, c_load, NULL)) s2
      INTO s1, s2
    FROM course c
      JOIN prefer p
        ON p.course_id = c.id
      WHERE staff_id = sid;
    
    UPDATE staff SET sem = IF(s1 > s2, 1, 2) WHERE id = sid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
I have defined following in a ResourceDictionary: <DockPanel x:Key=errorDisplay LastChildFill=False> <Border Background=Red DockPanel.Dock=Top> <TextBlock
In my .htaccess file I have defined following rule, RewriteRule t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA] The
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
I have defined the following struct in C: typedef struct point{ float x; float
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();
I have defined the following ApplicationManifest file the problem is that i have created
If I have defined the following types: type category = Noun | Verb |
Let's say I have defined the following class: public abstract class Event { public

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.