I have a very unusual question that involves matching data with similar values in two separate tables in SQL Server. for example, I have two tables:
The first table contains the following data:
- JobID (int),
- AssignmentDate(date),Location(nvarchar(MAX))
The second table contains the following data:
- Date(date), Start_time(nvarchar(MAX)),
- End_Time(nvarchar(MAX)), Begining)Ometer(int),
- Ending_Ometer(int), Mileage(float),
- To_location_Address(nvarchar(MAX)).
I created the folllowing query in SQL to generate a view so I can examine the data for validity:
SELECT dbo.KodakITAssignments.AssignmentDate,
dbo.KodakIT_all_trips_2019.Date,
dbo.KodakIT_all_trips_2019.Start_Time,
dbo.KodakIT_all_trips_2019.End_Time,
dbo.KodakIT_all_trips_2019.Beginning_Odometer,
dbo.KodakIT_all_trips_2019.Ending_Odometer,
dbo.KodakIT_all_trips_2019.Mileage_mi,
dbo.KodakITAssignments.JobID,
dbo.KodakITAssignments.Location,
dbo.KodakIT_all_trips_2019.To_Location_Address
FROM dbo.KodakIT_all_trips_2019 RIGHT OUTER JOIN
dbo.KodakITAssignments
ON dbo.KodakIT_all_trips_2019.Date = dbo.KodakITAssignments.AssignmentDate
My results are not quite satisfacotry. Here is an example of my results:
11/26/2019 11/26/2019 8:51 PM 9:12 PM 89053 89062 9 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 1701 Earl St, Union, NJ 07083
11/26/2019 11/26/2019 8:11 PM 8:18 PM 89052 89053 1.4 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 200 Varick St, New York, NY 10014
11/26/2019 11/26/2019 7:57 PM 8:01 PM 89051 89052 0.7 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 62 W 14th St, New York, NY 10011
11/26/2019 11/26/2019 7:39 PM 7:41 PM 89051 89051 0.3 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 14 6th Ave, New York, NY 10013
11/26/2019 11/26/2019 4:29 PM 4:50 PM 77846 77854 7.7 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 1701 Earl St, Union, NJ 07083
11/26/2019 11/26/2019 3:41 PM 3:42 PM 89051 89051 0.1 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 225 Broadway, Suite 2130, New York NY 10007
11/26/2019 11/26/2019 3:27 PM 3:28 PM 89051 89051 0.3 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 101 Barclay Street, New York, NY 10007
11/26/2019 11/26/2019 3:11 PM 3:28 PM 77843 77846 3.4 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 116 Elmer St, Westfield, NJ 07090
11/26/2019 11/26/2019 11:30 AM 11:40 AM 89049 89051 2.3 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 260 Broadway, New York, NY 10007
11/26/2019 11/26/2019 11:03 AM 11:24 AM 89037 89049 12.1 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 175 12th St, Jersey City, NJ 07310
11/26/2019 11/26/2019 11:02 AM 11:17 AM 77837 77843 5.5 125272 114-116 Quimby Street, westfield, NJ 07090 ,Westfield ,US 570 South Ave East, Building G, Suite F, Cranford, NJ 07016
10/21/2019 10/21/2019 7:37 PM 7:48 PM 87965 87967 2.2 119748 41 Main St, Millburn, NJ 07041, USA ,US 1701 Earl St, Union, NJ 07083
I would like to keep records from KodakIT_all_trips_2019 where the City and Zip Copes from both Location are a match; however, I do not have an exact location data set in the columns.
How do I filter the data in this case?
I am open to using SQL, R or Python to filter the data; what ever approach works best is okay, as long as I wind-up with a single record for the KodakItAssignments record.
Thamk you for the reply and guidance.