If they're always squares, perhaps something like this?
WITH Squares
(
Upperleft_X, Upperleft_Y, Upperright_X, Upperright_Y
,Lowerleft_X, Lowerleft_Y, Lowerright_X, Lowerright_Y, Cell
) AS (
SELECT 0, 0, 100, 0, 0, 100, 100, 100, 'A1'
UNION ALL SELECT 0, 101, 100, 101, 0, 200, 100, 200, 'B1'
UNION ALL SELECT 101, 0, 200, 0, 101, 100, 200, 100, 'A2'
UNION ALL SELECT 101, 101, 200, 101, 101, 200, 200, 200, 'B2')
,Points (n, x, y) AS (
SELECT 1, 25, 130
UNION ALL SELECT 2, 105, 40)
SELECT a.n, b.Cell, x, y, Upperleft_X, Upperright_X, Lowerleft_X, Lowerright_X
, Upperleft_Y, Upperright_Y, Lowerleft_Y, Lowerright_Y
FROM Points a
JOIN Squares b
ON (x BETWEEN Upperleft_X AND Lowerright_X AND
y BETWEEN Upperleft_Y AND Lowerright_Y);
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St