Ok.. Try running this code twice or thrice and confirm whether you are receiving any errors or not..
If Object_ID('tempdb..#SalesHeader1') Is Not Null
Drop Table #SalesHeader1
Create table #SalesHeader1 (SalesHeaderID int, CustomerID int, Route Varchar(50), Driver varchar(100),InvoiceNumber varchar(7));
If @DailyRouteDeliveryID Is Null
INSERT into #SalesHeader1 (SalesHeaderID, CustomerID, Route, Driver ,InvoiceNumber )
Select h.SalesHeaderID, h.CustomerID, r.Route, dbo.Driver4RouteDate(h.DeliveryDate,h.RouteID) As Driver, h.InvoiceNumber
From tblSalesHeader h Join tblRoute r On r.RouteID = h.RouteID
Where h.SalesHeaderID = @SalesHeaderID;
ELSE
INSERT into #SalesHeader1 (SalesHeaderID, CustomerID, Route, Driver ,InvoiceNumber )
Select h.SalesHeaderID, h.CustomerID, r.Route, dbo.DriverName(drd.DriverID) As Driver, h.InvoiceNumber
From tblSalesHeader h Join tblDailyRouteDelivery drd On drd.DailyRouteDeliveryID = h.DailyRouteDeliveryID Join tblRoute r On r.RouteID = h.RouteID
Where h.DailyRouteDeliveryID = @DailyRouteDeliveryID;