Question
I am a beginner and need help: I have to convert my SQL query into a stored procedure. this is my original query : SELECT
I am a beginner and need help: I have to convert my SQL query into a stored procedure. this is my original query :
SELECT TM.MaintenanceID, TM.TruckNumber, TI.TruckDescription, TI.TruckCurrentMileage, LUMT.MaintenanceType, LUTT.TruckType, TM.MaintenanceStartDate, TM.MaintenanceEndDate, LUTB.TruckBodyType FROM TruckMaintenance AS TM
JOIN dbo.TruckInformation AS TI on TI.TruckNumber = TM.TruckNumber
JOIN dbo.LUTruckType AS LUTT ON LUTT.TruckTypeID = TI.TruckTypeID
JOIN dbo.LUMaintenanceType AS LUMT ON LUMT.MaintenanceTypeID = TM.MaintenanceTypeID
JOIN dbo.LUTruckBodyType AS LUTB ON LUTB.TruckBodyTypeID = TI.TruckBodyTypeID
WHERE MaintenanceStartDate BETWEEN '2018-01-01' AND '2018-12-31'
ORDER BY LUTT.TruckType ASC, TM.MaintenanceStartDate ASC.
This is my stored procedure that when i execute results in nothing
CREATE PROCEDURE [dbo].[TruckMaintenanceDates] (@MaintenanceStartDate date, @MaintenanceEndDate date)
AS
BEGIN
SELECT TM.MaintenanceID,
TM.TruckNumber,
TI.TruckDescription,
TI.TruckCurrentMileage,
LUMT.MaintenanceType,
LUTT.TruckType,
TM.MaintenanceStartDate,
TM.MaintenanceEndDate,
LUTB.TruckBodyType
FROM TruckMaintenance AS TM
JOIN dbo.TruckInformation AS TI
on TI.TruckNumber = TM.TruckNumber
JOIN dbo.LUTruckType AS LUTT
ON LUTT.TruckTypeID = TI.TruckTypeID
JOIN dbo.LUMaintenanceType AS LUMT
ON LUMT.MaintenanceTypeID = TM.MaintenanceID
JOIN dbo.LUTruckBodyType AS LUTB
ON LUTB.TruckBodyTypeID = TI.TruckBodyTypeID
WHERE
MaintenanceStartDate BETWEEN @MaintenanceStartDate AND @MaintenanceEndDate
ORDER BY LUTT.TruckType ASC,
TM.MaintenanceStartDate ASC
SET NOCOUNT ON;
END
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started