Inline Table-Valued Function for Orders in a Date Range
×
Join our community on Telegram!
Join the biggest community of Pharma students and professionals.
Inline Table-Valued Function for Orders in a Date Range
orders table:

Query Explanation:
-
Procedure Definition: We create a procedure
GetOrdersByDateRangethat acceptsStartDateandEndDateas parameters. -
SELECT Query: Inside the procedure, we select orders from the
Orderstable where theOrderDateis between the given start and end dates. -
Calling Procedure: We use the
CALLstatement 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:

