Dataset SQL Query (Tutorial) teaches you to:
Prerequisites:
SQLite:
ProductionDB
SQL Server:
ProductionDB
SqlClient
Data Source=SERVER\INSTANCE;Initial Catalog=Production;Integrated Security=True
MySQL:
MySQLData
MySQL
Server=localhost;Database=scada;Uid=user;Pwd=password;
Get Current Orders:
ActiveOrders
ProductionDB
sql
SELECT
OrderID,
ProductName,
Quantity,
DueDate,
Status
FROM Orders
WHERE Status = 'Active'
ORDER BY DueDate
Create query with parameters:
Production by Date:
ProductionReport
sql
SELECT
ProductID,
SUM(Quantity) as Total,
AVG(Quality) as AvgQuality
FROM Production
WHERE ProductionDate BETWEEN @StartDate AND @EndDate
AND Line = @LineNumber
GROUP BY ProductID
Parameters:
Bind parameters to tags:
Report_StartDate
Report_EndDate
Selected_Line
@Dataset.Query.ActiveOrders
Call SP:
UpdateInventory
sql
EXEC sp_UpdateInventory
@ProductID = @ProductID,
@Quantity = @Quantity,
@Location = @Location
Create insert query:
sql
INSERT INTO EventLog
(Timestamp, EventType, Description, UserName, TagValue)
VALUES
(GETDATE(), @EventType, @Description, @User, @Value)
Execute from script:
csharp
@Dataset.Query.LogEvent.Execute(
"@EventType", "Alarm",
"@Description", "High Temperature",
"@User", @Client.UserName,
"@Value", @Tag.Temperature
);
Recipe Table:
Recipes
ProductionDB
RecipeData
RecipeID
Access in scripts:
csharp
DataRow recipe = @Dataset.Table.Recipes.SelectRow("RecipeID=101");
@Tag.Recipe_Name = recipe["Name"];
@Tag.Recipe_Temp = recipe["Temperature"];
Create scheduled task:
csharp
public void UpdateProductionMetrics()
{
// Run query every hour
@Dataset.Query.ProductionReport.Execute();
// Store results in tags
DataTable dt = @Dataset.Query.ProductionReport.ResultData;
@Tag.TotalProduction = dt.Compute("SUM(Total)", "");
}