Advertisement
JanuszKowalski123

10. hierarchyid 2

May 9th, 2024
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. -- Tworzenie zmiennych dla współrzędnych geograficznych i geometrycznych
  2. DECLARE @latitude DECIMAL(9, 6), @longitude DECIMAL(9, 6);
  3. DECLARE @point GEOMETRY;
  4. DECLARE @hierarchy HIERARCHYID;
  5. DECLARE @device_description XML;
  6.  
  7. -- Pętla wypełniająca tabelę
  8. DECLARE @i INT = 1;
  9. WHILE @i <= 50
  10. BEGIN
  11. -- Generowanie losowych danych dla każdej kolumny
  12. SET @latitude = RAND() * 180 - 90;
  13. SET @longitude = RAND() * 360 - 180;
  14. SET @point = GEOMETRY::Point(@latitude, @longitude, 4326);
  15. SET @hierarchy = HIERARCHYID::GetRoot();
  16. SET @device_description = '<description>Device ' + CAST(@i AS NVARCHAR(5)) + '</description>';
  17.  
  18. -- Wstawianie danych do tabeli
  19. INSERT INTO Renewable_Energy_Devices (device_id, device_status, device_power, company_id, device_location, device_location_geom, device_hierarchy, device_description)
  20. VALUES (
  21. 'Device_' + CAST(@i AS NVARCHAR(5)), -- device_id
  22. CAST(RAND() * 6 AS INT), -- device_status
  23. CAST(RAND() * 1000 AS DECIMAL(18, 0)), -- device_power
  24. CAST(RAND() * 10 AS INT) + 1, -- company_id
  25. GEOGRAPHY::Point(@latitude, @longitude, 4326), -- device_location
  26. @point, -- device_location_geom
  27. @hierarchy.GetDescendant(NULL, NULL), -- device_hierarchy
  28. @device_description -- device_description
  29. );
  30.  
  31. SET @i = @i + 1;
  32. END;
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement