How-to
Show SQL Data on a FactoryTalk View Screen by Date Range
Short answer
Use the Data Grid object, available in FactoryTalk View SE from v12, bound to a query that filters the timestamp column with Timestamp >= @Start AND Timestamp < @End. Verify the query in SSMS first, index the timestamp column, and refresh on an Apply button rather than on a timer.
On this page
- Which FactoryTalk View object shows SQL rows in a grid?
- Why run the query in SSMS before building the screen?
- How do I write the date-range query so it stays fast?
- How do I build the Data Grid screen in FactoryTalk View Studio?
- How many rows will a 24-hour date range return?
- Why is the grid empty or ignoring the dates I enter?
- How do I test the grid screen before release?
- Questions asked
Data is logging into SQL Server, but no screen reads it back: logging and display are separate paths, and the logger only writes. On FactoryTalk View SE v12 and later, so including your v15, the read-back object is the Data Grid — bind it to a query with Timestamp >= @Start AND Timestamp < @End, hold the start and end values in tags the operator edits, and refresh from an Apply button. Prove that query in SQL Server Management Studio (SSMS) before building anything, because no grid property fixes a wrong SELECT. If the write path itself still needs design work, start from logging PLC data through a gateway rather than the HMI.
Which FactoryTalk View object shows SQL rows in a grid? #
The Data Grid object, added to FactoryTalk View SE in version 12 and present in v15, is built for exactly this: a bound query rendered as rows and columns, while a Numeric Indicator only suits one live value at a time. Before the Data Grid existed, getting database rows onto an SE display meant VBA scripting or an ActiveX control, and that remains the fallback on older revisions. Configure the object through its Data Grid Properties dialog box, where the data source and query options live; the installed help documents the options per version. Split the job by intent: Numeric Indicators on the section screens for what a value is right now, and one Data Grid screen for what the rows were between two timestamps.
Why run the query in SSMS before building the screen? #
Run the exact query with literal start and end dates in SSMS first: if it returns the right rows there, the database side is proven and every remaining fault sits on the display side. Debug in that order, because a grid bound to a broken SELECT cannot be repaired from the screen. A query that runs in SSMS but returns nothing in the client application is a known pattern with its own failure modes — read why a SQL query returns no records but runs in SSMS before assuming the grid is at fault. Nothing pushes logged rows back to a display; the screen issues its own SELECT, and the time window belongs in that WHERE clause, not in a client-side filter over a large result.
How do I write the date-range query so it stays fast? #
Filter the timestamp column with a half-open range, Timestamp >= @Start AND Timestamp < @End, on an indexed column, and cap the rows returned — that combination is what keeps a wide range from freezing the client. The half-open bounds include a row logged exactly at the start and exclude one logged exactly at the end, so no boundary row is double-counted when windows are stepped. Then prepare the database side:
- Open each logging table in SSMS and note the exact data type of the timestamp column — datetime, datetime2, or text — and compare like with like in the query.
- Confirm whether the logger writes UTC or local time, pick one convention for the operator inputs, and convert in the query if they differ.
- Add a nonclustered index on the timestamp column of every table queried by range; without it, each range search scans the whole table.
- Write one view or one parameterized stored procedure per query shape — one section's rows between a start and an end — and keep the SELECT list to the columns the grid shows.
- Cap the result with a row limit such as
TOP (5000)and surface a message when the cap is hit. - Give the screen a read-only SQL login on those views, never the admin account the logger uses.
- Never concatenate operator text into the SQL string; validate the dates and pass them as parameters or through the stored procedure.
With one table per section on a single server — 80 tables in a plant of 80 PLCs — never union them behind one screen. The operator picks a section, and the query targets that section's table or view.
How do I build the Data Grid screen in FactoryTalk View Studio? #
Place a Data Grid object on a display, bind it to the prepared query, hold the start and end values in tags the operator edits, and refresh from an Apply button — not from a keystroke or a fast timer. Build it in this order:
- Verify the ODBC data source exists on every machine that will run the screen, not only on the server — the same kind of system data source the data log configuration creates — and test the connection from each machine.
- Place a Data Grid object on a new display and open its Data Grid Properties dialog box to point it at the data source and the query.
- Create tags or display parameters for the start and end values, plus a selector for the section.
- Put input objects for those tags beside the grid so the operator can type the window.
- Wire the start, end, and section values into the query so the grid runs a bounded SELECT against one section's view or procedure.
- Add the Apply button that triggers the refresh, and a visible message when the row cap is hit.
- Keep Numeric Indicators on the section screens for current values; the grid carries the history.
How many rows will a 24-hour date range return? #
At one row every 10 seconds, a 24-hour window is 8,640 rows, and a 30-day table holds 259,200 rows — the count an unindexed query scans on every refresh. Work it for your own numbers; the following is an illustrative example, not a measured result:
- Logging period: 10 s per row.
- Rows per day: 86,400 s ÷ 10 s = 8,640 rows.
- One 24-hour window: 1 × 8,640 = 8,640 rows.
- 30 days retained: 8,640 × 30 = 259,200 rows.
- With a 5,000-row cap: 8,640 > 5,000, so a full-day request truncates; the longest full window the cap allows is 5,000 × 10 s = 50,000 s ≈ 13.9 h.
The decision follows the arithmetic: at a 10 s period and a 5,000-row cap, limit the operator's span to 13 hours or aggregate the data before display, and the index decides whether the query reads only the window's rows or the whole retained table. Substitute your real logging period and retention, and the same two products give your span limit and your scan size.
Why is the grid empty or ignoring the dates I enter? #
An empty grid over a range that has data is almost always a timestamp data type or UTC/local mismatch, while a grid that shows every row means the start and end values never reached the query. Diagnose from the symptom:
| What you see | Likely cause | First check |
|---|---|---|
| Grid empty for a range that has data | Timestamp type or UTC/local mismatch; window sits outside logged data | Run the query in SSMS with the same literal dates |
| Grid shows every row, dates ignored | Start and end values never reach the query | Hard-code two dates in the query and confirm the result shrinks |
| Times shifted by whole hours | Logger writes UTC while the operator enters local time, or the reverse | Compare a known event time in SSMS against the plant clock |
| Screen stalls on open or on Apply | Unbounded range, no index on the timestamp column, too many joins | Read the execution plan in SSMS; count the rows for the range |
| Works on the server, fails on a client | ODBC data source or SQL login differs on that machine | Compare the data source and login on the failing machine |
Every row in that table is checked in SSMS first, on the machine that fails, under the login the screen uses.
How do I test the grid screen before release? #
Match the grid's row count against SSMS for one known window, test both boundary edges and an empty window, then time the widest allowed range on a client machine under the read-only login the screen will use. Concretely:
- Pick a short window with known data; the SSMS count and the screen count must match.
- End one test window exactly on a logged timestamp and start another exactly on one: the half-open range includes the start row and excludes the end row.
- Request an empty window and confirm the grid clears instead of showing stale rows.
- Enter the widest range an operator can reach and measure open and refresh time on a client, not only on the server.
- Repeat on a second client under the screen's own login, because a missing data source or a permissions gap appears only there.
- Decide how far back operators may look and confirm the logging side keeps rows that long — the grid can only show rows that still exist, the same discipline as verifying HMI historical trend retention before committing.
Release the screen when the counts match, the edges behave, the empty window clears, and the widest allowed range opens in a time the operator accepts on the slowest client.
Questions asked
Do I still need Numeric Indicators if the grid shows the data?
Yes, keep them for current values. A Numeric Indicator bound to the PLC tag updates continuously and answers what a value is right now; the Data Grid answers what the rows were between two timestamps. Preset the grid's start and end to the last hour when the screen opens, so the first Apply already shows data instead of an empty grid.
One screen or 80 screens for 80 section tables?
One screen with a section selector. The selector value decides which table or view the query targets, so each refresh reads one section. Eighty separate screens duplicate the layout and drift apart; one union across all tables multiplies every window's row count by 80 and is what stalls clients.
Should the grid query use the same SQL login as the logger?
No. The logger needs insert rights on the logging tables; the screen needs read-only rights on the views. Separate logins mean a mistake on the display side cannot delete or overwrite history, and auditing is simpler because logger traffic and operator queries are distinguishable.
How do I stop an operator from requesting a month at once?
Enforce a maximum span in the screen logic, for example reject any range over 7 days, and keep the row cap in the query as the hard backstop, with a visible message when it truncates. The span check tells the operator what to fix; the cap protects the client if the check is ever bypassed.