Advertisement
Guest User

Migration Settings

a guest
Feb 18th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. CREATE TABLE MigrationZoneMapping (serverId INT, sensorId INT, zoneId VARCHAR(50))
  2.  
  3. INSERT INTO MigrationZoneMapping (serverId, sensorId, zoneId) VALUES
  4. (ENTER_SERVER_ID_HERE, ENTER_SENSOR_ID_HERE, 'ZONE_ID_HERE'),
  5. (ENTER_SERVER_ID_HERE, ENTER_SENSOR_ID_HERE, 'ZONE_ID_HERE'),
  6. (ENTER_SERVER_ID_HERE, ENTER_SENSOR_ID_HERE, 'ZONE_ID_HERE')
  7.  
  8.  
  9.  
  10.  
  11. SELECT
  12. mzm.zoneId,
  13. CONVERT(
  14. VARCHAR(33),
  15. DATEADD(hour, DATEDIFF(hour, 0, sd.ServerDate), 0),
  16. 126
  17. ) + 'Z' as recordDate,
  18. CONVERT(INT, SUM(sd.ValueA)) as ins,
  19. CONVERT(INT, SUM(sd.ValueB)) as outs,
  20. 'ENTER_ORG_ID_HERE' as orgId
  21. FROM sensordata sd
  22. INNER JOIN sensors ss ON (sd.SensorId = ss.sensorId)
  23. INNER JOIN servers sr ON (ss.ServerId = sr.serverid)
  24. INNER JOIN MigrationZoneMapping mzm ON (sr.serverId = mzm.serverid AND ss.sensorId = mzm.sensorId)
  25. INNER JOIN Facility f ON (sr.ParentFacility = f.Facility)
  26. WHERE f.ParentRegion = ENTER_PARENT_REGION_ID_HERE
  27. GROUP BY
  28. DATEADD(hour, DATEDIFF(hour, 0, sd.ServerDate), 0),
  29. DATEADD(hour, (f.tzoffset / 10000), DATEADD(hour, DATEDIFF(hour, 0, sd.ServerDate), 0)), mzm.zoneId
  30. ORDER BY recordDate;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement