Instagram
youtube
Facebook
Twitter

Inline Table-Valued Function for Orders in a Date Range

Inline Table-Valued Function for Orders in a Date Range

orders table:

Query Explanation:

  1. Procedure Definition: We create a procedure GetOrdersByDateRange that accepts StartDate and EndDate as parameters.

  2. SELECT Query: Inside the procedure, we select orders from the Orders table where the OrderDate is between the given start and end dates.

  3. Calling Procedure: We use the CALL statement to execute the procedure with the date range you want.

 

SQL Query:

USE SalesInventoryDB;

-- Creating a stored procedure to fetch orders in a date range
DELIMITER //

CREATE PROCEDURE GetOrdersByDateRange(
    IN StartDate DATE,
    IN EndDate DATE
)
BEGIN
    SELECT * 
    FROM Orders
    WHERE OrderDate BETWEEN StartDate AND EndDate;
END //

DELIMITER ;



-- Once the procedure is created, you can call it like this:
CALL GetOrdersByDateRange('2023-01-01', '2024-12-31');

 

Output: