# Perspective- Trend a custom SQL query

**URL:** <https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 11, 2020, 12:02am UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581 "2020-09-11T00:02:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlos.aguero](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@carlos.aguero](https://forum.inductiveautomation.com/u/carlos.aguero)\
**Post date:** [September 11, 2020, 12:02am UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/1 "2020-09-11T00:02:03Z")

</div>

I can’t get perspective to trend a custom query.  
I’m using a time series chart and a named Querie

SELECT DateTime, LeftHeight  
FROM Shipping\_PostHeight  
WHERE DateTime \>‘2020-09-09 14:00’ ORDER BY DateTime DESC

when tested the Named Querie it shows all the values and columns with no issues

If I use a table it shows the data, but the DateTime column shows values instead of Dates  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9af858323a613df586bf64a2559aabc59ce93e2f.png)

and my Time Series Chart keeps throwing “Componen error”… I’m bindig the named querie as a dataset in the Table Series property

Does anyone have a basic example on how to trend and show data coming from SQL, not historian…?

thanks!

---

<div class="post-metadata">

**Author:** ![vrush.dahivalkar](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@vrush.dahivalkar](https://forum.inductiveautomation.com/u/vrush.dahivalkar)\
**Post date:** [September 11, 2020, 4:21am UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/2 "2020-09-11T04:21:10Z")

</div>

Hi

1.Under Query Binding see the Return Format is “auto” where you configure your named querie for chart.  
2. TimeSeriesChart - delate the ‘0’ Object under plots and add again

this might help you.

---

<div class="post-metadata">

**Author:** ![carlos.aguero](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@carlos.aguero](https://forum.inductiveautomation.com/u/carlos.aguero)\
**Post date:** [September 11, 2020, 1:28pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/3 "2020-09-11T13:28:07Z")

</div>

Returning format is in AUTO and deleted the o Obejct under plots… still the same error…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/7/c7f0ff6f7b68318b4f722670e533e7d5384a5a58.png)

Do you have any sample projects with trends using a SQL database (not history) that I can use as reference?  
thanks for the help.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 11, 2020, 2:13pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/4 "2020-09-11T14:13:38Z")

</div>

Did you try setting the return format to json?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 11, 2020, 2:21pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/5 "2020-09-11T14:21:20Z")

</div>

Sorry, forgot to ask what database you are using.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 11, 2020, 3:11pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/6 "2020-09-11T15:11:17Z")

</div>

Dang, I need coffee…

Where are you binding it in the chart? It needs to be in the ‘data’ portion of the series.

 ![2020-09-11_11-08-28](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/b/cb2e51194a308e1e51399741b0bf7a5cc1668341.png)

---

<div class="post-metadata">

**Author:** ![carlos.aguero](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@carlos.aguero](https://forum.inductiveautomation.com/u/carlos.aguero)\
**Post date:** [September 11, 2020, 11:44pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/7 "2020-09-11T23:44:59Z")

</div>

Jordan, I’m using Microsoft SQL. You were right, I was doing the binding in the wrong location.I did the binding in the ‘data’ of the series and it worked well… =)

I have a table with the same data, but my first column (Date Time) is showing values instead of the dates… Do you know how to set that column to show Date Time instead of values?..

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![schenk](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schenk](https://forum.inductiveautomation.com/u/schenk)\
**Post date:** [September 12, 2020, 3:54pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/8 "2020-09-12T15:54:53Z")

</div>

If you add the columns in the column configuration, it should format as a date. You can customize it by adjusting the dateFormat property.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/a/4a2d98f7faedaf351bb59a3ab5c6c852b99d03c7.png)

---

<div class="post-metadata">

**Author:** ![Andrii.Randiuk](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Andrii.Randiuk](https://forum.inductiveautomation.com/u/Andrii.Randiuk)\
**Post date:** [June 8, 2021, 12:09pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/9 "2021-06-08T12:09:47Z")

</div>

Hi) can you help me? What I do not right?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aa3a429134228069ff42f4ae6fe5b21a190ff624.png)

---

<div class="post-metadata">

**Author:** ![bryan\_jaimes](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bryan\_jaimes](https://forum.inductiveautomation.com/u/bryan_jaimes)\
**Post date:** [August 17, 2023, 5:15pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/10 "2023-08-17T17:15:29Z")

</div>

Try Putting your t\_stamp1 first in your query....For Example:  
Select  
t\_stamp1,Total\_count,singlecarrier\_count,doublecarrier\_count  
From  
(Select  
alltable.t\_stamp1 as t\_stamp1,  
alltable.InductTotal As Total\_count,  
alltable.singlecarrier\_count as singlecarrier\_count,  
alltable.doublecarrier\_count as doublecarrier\_count

From alltable  
Where (alltable.t\_stamp Between:starttime and :endttime)) basa

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 17, 2023, 7:01pm UTC](https://forum.inductiveautomation.com/t/perspective-trend-a-custom-sql-query/38581/11 "2023-08-17T19:01:18Z")

</div>

> [@Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831):
>
> This thread is intended as a short help file for all those struggling to post formatted code on the forum. Posting formatted code on the forum (and most others) is as simple as selecting the code and pressing the \</\> button. It works the same as applying Bold or Italic styles to your document. It preserves indentation and applies syntax highlighting. [How to post code]
