I have a table of X and Y values relating to points on a mapping grid where each pair of values reference the bottom left corner of each square which are spaced in 500 square metre increments for each value to form the points in a grid structure.
Here is an example of the table with some similar data with the XY_ID just being a concatenation of the X and Y values.
| XY_GridPointID | X_GridPoint | Y_GridPoint |
|---|---|---|
| 250000650000 | 250000 | 650000 |
| 250500650500 | 250500 | 650500 |
| 251000651000 | 251000 | 651000 |
| 251500651500 | 251500 | 651500 |
| 252000652000 | 252000 | 652000 |
| 252500652500 | 252500 | 652500 |
| 253000653000 | 253000 | 653000 |
| 253500653500 | 253500 | 653500 |
| 254000654000 | 254000 | 654000 |
| 254500654500 | 254500 | 654500 |
| 255000655000 | 255000 | 655000 |
I then have another Table with each row having a specific X and Y value which is more specific in terms of the values being down to the metre. So for instance a particular row has an X_Value of 252996 and a Y_Value of 652818.
What I would like to achieve is to be able to lookup the Grid table shown above and pull through the X_GridPoint and Y_GridPoint of where that particular row's X_Value and Y_Value are within in terms of the 500m increments.
So for the X_Value of 252996 and Y_Value of 652818, this would find the X_GridPoint of 252500 and Y_GridPoint of 652500 which is row 6 of the example table above. The Values will essentially be 'falling back' into whatever 500m grid point that precedes that value and it would never 'round up' to the next 500m grid point.
The table with the grid points will consist of around 25,000 rows of these combinations and looking to link to a large dataset with the specific X and Y Values, so wondered if anyone can suggest the best way to approach this and what would work best in terms of performance. Any ideas would be greatly appreciated.
Using SQL Server 2016