troubleshooting Question

Combining 2 SQL SP's

Avatar of MBoy
MBoy asked on
DatabasesMicrosoft SQL Server 2005Microsoft SQL Server 2008
10 Comments1 Solution199 ViewsLast Modified:
I need to combine the results from these two working SP's.  Any suggestions?
CREATE PROCEDURE [dbo].[GetAllLocationsWithVehicleName]
AS
BEGIN
      SELECT
            [GPRSDevice].[GPRSDeviceHardwareID],
            [Vehicle].[VehicleName],
            [Event].[4],
            [Event].[3],
            [Event].[2]
     FROM  [GPRSDevice], [Vehicle], [Event]
       WHERE [GPRSDevice].[VehicleID] = [Vehicle].[VehicleID]
            AND [GPRSDevice].[GPRSDeviceHardwareID] = [Event].[1]
   AND  [Event].[2] = (SELECT MAX( [2] ) FROM [Event] WHERE [1] = [GPRSDevice].[GPRSDeviceHardwareID] ) 
       ORDER BY [Vehicle].[VehicleName]
END
GO
********************************************************************************************************************
 
CREATE PROCEDURE [dbo].[GetTotalHoursByGPRSDeviceHardwareID]
(
     @GPRSDeviceHardwareID As varchar(50) 
)
AS
 
DECLARE @X As Int
DECLARE @Y As Int
DECLARE @Z As Int
 
 
BEGIN
 
		SET @X = 0
 
		IF EXISTS (SELECT 1 FROM HourMeter WHERE GPRSDeviceHardwareID = @GPRSDeviceHardwareID)
 
		SET @X = (SELECT SUM(LineDifference) FROM HourMeter WHERE GPRSDeviceHardwareID = @GPRSDeviceHardwareID)
 
		
		SET @Y = 0
 
		IF EXISTS (SELECT 1 FROM HourMeterHistory WHERE GPRSDeviceHardwareID = @GPRSDeviceHardwareID)
 
		SET @Y = (SELECT SUM(LineDifference) FROM HourMeterHistory WHERE GPRSDeviceHardwareID = @GPRSDeviceHardwareID)
 
		
		SET @Z = 0
 
		IF EXISTS (SELECT 1 FROM HourMeterDifference WHERE GPRSDeviceHardwareID = @GPRSDeviceHardwareID)
 
		SET @Z =(SELECT HourMeterDifference FROM HourMeterDifference WHERE GPRSDeviceHardwareID = @GPRSDeviceHardwareID)
 
RETURN @X + @Y + @Z
 
END
GO
ASKER CERTIFIED SOLUTION
wilje

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros