Created
July 16, 2023 07:32
-
-
Save exemplum100/48add17730bb2518548692f7b4ed9690 to your computer and use it in GitHub Desktop.
Использование типа GEOGRAPHY для adhoc отчета
This file contains 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