Advertisement
JanuszKowalski123

10. hierarchyid 7

May 9th, 2024 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.11 KB | None | 0 0
  1. DECLARE @latitude DECIMAL(9, 6), @longitude DECIMAL(9, 6);
  2. DECLARE @point GEOMETRY;
  3. DECLARE @device_hierarchy HIERARCHYID;
  4. DECLARE @device_description XML;
  5.  
  6. DECLARE @i INT = 1;
  7. WHILE @i <= 50
  8. BEGIN
  9.     SET @latitude = RAND() * 180 - 90;
  10.     SET @longitude = RAND() * 360 - 180;
  11.     SET @point = GEOMETRY::Point(@latitude, @longitude, 4326);
  12.  
  13.     -- Tworzenie hierarchii z użyciem losowej wartości dodanej do korzenia
  14.     SET @device_hierarchy = HIERARCHYID::GetRoot().GetDescendant(NULL, NULL);
  15.  
  16.     SET @device_description = '<description>Device_' + CAST(@i AS NVARCHAR(5)) + '</description>';
  17.  
  18.     INSERT INTO Renewable_Energy_Devices (device_id, device_status, device_power, company_id, device_location, device_location_geom, device_hierarchy, device_description)
  19.     VALUES (
  20.         'Device_' + CAST(@i AS NVARCHAR(5)),
  21.         CAST(RAND() * 6 AS INT),
  22.         CAST(RAND() * 1000 AS DECIMAL(18, 0)),
  23.         CAST(RAND() * 10 AS INT) + 1,
  24.         GEOGRAPHY::Point(@latitude, @longitude, 4326),
  25.         @point,
  26.         @device_hierarchy,
  27.         @device_description
  28.     );
  29.  
  30.     SET @i = @i + 1;
  31. END;
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement