Created
December 19, 2024 05:43
-
-
Save exemplum100/bf103c1ab80d75ef815ce8e4fcc4e6f0 to your computer and use it in GitHub Desktop.
Использование типа GEOGRAPHY для отчета
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE geo_kursor CURSOR LOCAL FOR | |
SELECT k.pin,k.lat,k.long,k.geo,k.reciv FROM #koors3 AS k | |
ORDER BY k.reciv | |
OPEN geo_kursor | |
FETCH NEXT FROM geo_kursor | |
INTO @pinfirst,@latg,@longg,@geocurs,@receiv ---LOOK | |
WHILE @@FETCH_STATUS=0 | |
BEGIN | |
SET @userloc = geography::Point(@latg, @longg, 4326).STBuffer(@km) | |
SET @checkgeo1 = (SELECT TOP (1) t.checkgeo FROM #t2 AS t WHERE t.checkpin=@pinfirst ORDER BY t.receivedm DESC ) | |
IF @checkgeo1 IS NULL OR (SELECT @checkgeo1.STIntersects(@userloc))!=1 | |
BEGIN | |
SET @counterready=(SELECT COUNT(DISTINCT k.pin) FROM #koors3 AS k WHERE @userloc.STIntersects(geo)=1) | |
IF @counterready>4 | |
BEGIN | |
INSERT INTO #t1 (userlocation,latx,long,counts) | |
SELECT @userloc, @latg,@longg,@counterready | |
PRINT 'go next' | |
PRINT CAST (@counterready AS VARCHAR(45)) | |
INSERT INTO #t2 | |
SELECT @pinfirst,@userloc,@receiv,@latg,@longg | |
end | |
END | |
FETCH NEXT FROM geo_kursor | |
INTO @pinfirst,@latg,@longg,@geocurs,@receiv | |
END | |
CLOSE geo_kursor | |
DEALLOCATE geo_kursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment