Lab 11.2 – Query the Tier-2 Historian Server
Step 7. In Object Explorer, click the Connect Object Explorer.
The Connect to Server dialog box appears.
Step 8. In the Server name field, enter the name of your Tier-2 Historian Server.
Step 9. Leave the other values as default and click Connect.
Step 10. In Object Explorer, verify that both servers are now listed.
Step 11. In the SQL Management Studio menu, select Query | Connection and click Change Connection.
The Change Connection command is used to switch between the servers available for running queries.
The Connect to Database Engine dialog box appears.
Step 12. Select the Tier-2 Server you need to connect to and click Connect.
Step 13. Verify that the Runtime database is selected.
Now you are ready to continue with Example 5 in your query.
--TIER-2 REPLICATION
--To be able to execute the following queries, connect the SQL Server
--Management Studio to your Tier-2 Historian and select the Runtime
--database. Check your lab steps for further details.
--Example 5
--In this query, you will retrieve historized data from your Tier-2
--Historian Server for the simple replication tags.
--Replace the XXX string with the name of your Tier-1 Historian Server.
--Remember, the replicated tag scheme includes the name of the Historian
--Server where the original tag resides, that is, your Tier-1.
SELECT DateTime, TagName, Value
FROM HISTORY
WHERE TagName='XXX.M100.Agitator.Speed.PV'
AND DateTime > Dateadd(mi, -30, Getdate())
AND DateTime <= Getdate()
Lab 11 – Querying Replicated Data 4-53
Historian Server 2014 for System Platform
--Example 6
--Wide table query
--Replace the XXX string with the name of your Tier-1 Historian Server.
SELECT * FROM OpenQuery(InSQL, '
SELECT DateTime, [XXX.M200.Agitator.Temp.PV],
[XXX.M100.Agitator.Temp.PV]
FROM WideHistory
WHERE DateTime > Dateadd(mi, -15, Getdate())
AND DateTime <= Getdate()
')
Note: Leave the Microsoft SQL Server Management Studio open. It will be used in subsequent
labs.