Advertisement
JanuszKowalski123

10. hierarchyid 9

May 9th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. -- Tworzenie hierarchii dla pierwszego urządzenia
  2. DECLARE @root HIERARCHYID;
  3. SET @root = HIERARCHYID::GetRoot();
  4. DECLARE @child HIERARCHYID;
  5. SET @child = @root.GetDescendant(NULL, NULL);
  6.  
  7. -- Aktualizacja wartości w kolumnie device_hierarchy
  8. UPDATE Renewable_Energy_Devices
  9. SET device_hierarchy = @child
  10. WHERE device_id = 'Device_1';
  11.  
  12. -- Aktualizacja wartości w kolumnie device_hierarchy dla wartości między 2 a 50
  13. DECLARE @j INT = 2;
  14. WHILE @j <= 50
  15. BEGIN
  16. SET @child = @child.GetDescendant(NULL, NULL);
  17.  
  18. UPDATE Renewable_Energy_Devices
  19. SET device_hierarchy = @child
  20. WHERE device_id = 'Device_' + CAST(@j AS NVARCHAR(5));
  21.  
  22. SET @j = @j + 1;
  23. END;
  24.  
  25. -- Wyświetlenie zaktualizowanych rekordów
  26. SELECT * FROM Renewable_Energy_Devices;
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement