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

  • Home
  • SEARCH
  • 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 7487821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:39:52+00:00 2026-05-29T14:39:52+00:00

This stored procedure is taking care of material reservations. The basic idea is that

  • 0

This stored procedure is taking care of material reservations. The basic idea is that it checks how much of THIS material are already hired and if there are still materials in stock i will insert a new order. If there is already a reservation for this material for this reservation id i am updating the amount.

Maybe im doing something wrong but when i try to add a new reservation it works. The update NEVER works and when there is already a reservation for an specif material id it’s not possible to rent it with another reservation id.

I give you an example:

CALL aantal_besch_mat_van_tot('2007-03-13','2007-03-14',15,6,50,'procedure test lol');

Ok so this works but when i execute it again the amount 50 should go to 50 + previous so it should be 100 it never updates.

Also when you would hire the same material with another reservation id it’s not working.
example:

CALL aantal_besch_mat_van_tot('2007-03-13','2007-03-14',15,7,50,'Im hiring this material');

That is also not working.

I already printed out al value’s and there getting the right amount.

Here you can find my stored procedure code:

    DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `fabiola`.`aantal_besch_mat_van_tot`(IN `p_datum_van` date,IN `p_datum_tot` date,IN `p_mat_id` int, IN `p_res_id` int, IN `p_nodig` int, IN `p_mat_opmerking` VARCHAR(255))

BEGIN
    DECLARE aantal INT DEFAULT 0;
    DECLARE tot  INT DEFAULT 0;
    DECLARE upda INT DEFAULT 0;
    DECLARE nieuwa INT DEFAULT 0;
    DECLARE voriga INT DEFAULT 0;
    DECLARE test INT DEFAULT 0;
    DECLARE res_van datetime;
    DECLARE res_tot datetime;

    -- Overeenkomstige data selecteren
    SELECT r.incheckdatum, r.uitcheckdatum FROM reservaties r
    WHERE r.id = p_res_id
    INTO res_van, res_tot;

        SELECT mpr.aantal FROM materialen_per_reservatie mpr
        WHERE mpr.materialen_id = p_mat_id AND
            (
            (p_datum_van >= mpr.datum_van AND p_datum_tot <= mpr.datum_tot) -- overlap: binnen
            OR (p_datum_van <= mpr.datum_van AND p_datum_tot >= mpr.datum_van) -- overlap: voor+in
            OR (p_datum_van <= mpr.datum_tot AND p_datum_tot >= mpr.datum_tot) -- overlap: na+in
            OR (p_datum_van <= mpr.datum_van AND p_datum_tot >= mpr.datum_tot) -- overlap:omsluitend
            )
        INTO aantal;

        -- The total amount of materials
        SELECT m.aantal_beschikbaar FROM materialen m
        WHERE m.id = p_mat_id
        INTO tot;
        -- The test variable is holding the amount of materials that's still available
        SELECT tot-aantal INTO test;
        -- Checking if im not ordering more then there is available
        IF p_nodig < test THEN
            -- Checking if this material is already hired from this reservation id
            SELECT mpra.id, mpra.aantal FROM materialen_per_reservatie mpra
            WHERE (mpra.reservaties_id = p_res_id
            AND   mpra.materialen_id = p_mat_id) INTO upda, voriga;
            -- if voriga is bigger then zero it means that there is already an reservatie for this material for this reservation so im not inserting but updating
            IF voriga > 0 THEN
                -- Selecting the previous amount and add it with the p_nodig amount
                SELECT voriga+p_nodig INTO nieuwa;
                UPDATE materialen_per_reservatie SET materialen_per_reservatie.aantal = nieuwa WHERE reservaties_id = p_res_id AND materialen_id = p_mat_id;
            ELSE
                -- There is no reservation for this material with this reservation id so i my insert a new row
                INSERT INTO materialen_per_reservatie(reservaties_id, materialen_id, aantal, effectief_gebruikt, opmerking, datum_van, datum_tot) VALUES (p_res_id, p_mat_id, p_nodig, p_nodig, p_mat_opmerking, p_datum_van, p_datum_tot);
            END IF;
        END IF;
END$$

I tested out both INSERT / UPDATE query’s separate and they are working.

  • 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-29T14:39:53+00:00Added an answer on May 29, 2026 at 2:39 pm

    Where are the quotes around your date values?

    Try this:

    call aantal_besch_mat_van_tot('2007-03-13', '2007-03-14', 15, 6, 50, 'Im hiring this material');
    

    Note dates are like '2007-03-13', not 2007-03-13, which is literally the number 1991 (ie 2007 – 3 – 13 = 1991)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well I have this MySQL stored procedure that I wrote and if I run
I've got a mySql stored procedure that looks like this-- delimiter | create procedure
So basically I have this relatively long stored procedure. The basic execution flow is
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,
Can anyone please point out what im doing wrong with this Stored Procedure please.
This code involves a recursive Stored Procedure call and a not so great method
I have a mysql stored procedure from this ( google book ), and one
I have a stored procedure and if the stored procedure does this: SELECT 0
If I have this stored proc definition minus the body ALTER PROCEDURE sp_AlloctionReport(@where NVARCHAR(1000),
here's the stored procedure i wrote.In this proc p_subjectid is an array of numbers

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.