# FSQL Group execution error

**URL:** <https://forum.inductiveautomation.com/t/fsql-group-execution-error/719>\
**Category:** Archived Topics\
**Created:** [July 7, 2008, 8:27pm UTC](https://forum.inductiveautomation.com/t/fsql-group-execution-error/719 "2008-07-07T20:27:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamabelew](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@adamabelew](https://forum.inductiveautomation.com/u/adamabelew)\
**Post date:** [July 7, 2008, 8:27pm UTC](https://forum.inductiveautomation.com/t/fsql-group-execution-error/719/1 "2008-07-07T20:27:42Z")

</div>

Hi All,

I am getting an error when running the following SQL command in a group:

SELECT TimeDiff((SELECT EndTime FROM Table WHERE Table\_ndx = 10),  
(SELECT BeginTime FROM Table WHERE Table\_ndx = 10))

The message states that " Error executing query: You have an error in your SQL Syntax; check the manual that corresponds to your MySql server version for the right syntax to use near ‘:22:07)’ at line 1"

(The time difference is 22min 07sec)

Any Ideas?

thanks,

Adam

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [July 7, 2008, 8:59pm UTC](https://forum.inductiveautomation.com/t/fsql-group-execution-error/719/2 "2008-07-07T20:59:22Z")

</div>

Yikes, I don’t know why you’re getting that error, but that query is bizarre.

Try:

```auto
SELECT TimeDiff(EndTime, BeginTime) FROM Table WHERE Table_ndx = 10
```

Might want to pick up a copy of this book:  
[amazon.com/Learning-SQL-Alan … 231&sr=8-2](http://www.amazon.com/Learning-SQL-Alan-Beaulieu/dp/0596007272/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1215464231&sr=8-2)

---

<div class="post-metadata">

**Author:** ![adamabelew](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@adamabelew](https://forum.inductiveautomation.com/u/adamabelew)\
**Post date:** [July 8, 2008, 1:29am UTC](https://forum.inductiveautomation.com/t/fsql-group-execution-error/719/3 "2008-07-08T01:29:39Z")

</div>

Funny part is, I get the proper result in the “value” portion of the group. I get the error message after that.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [July 8, 2008, 2:54am UTC](https://forum.inductiveautomation.com/t/fsql-group-execution-error/719/4 "2008-07-08T02:54:23Z")

</div>

Is the action item writing back to a column? What type is the column?

---

<div class="post-metadata">

**Author:** ![adamabelew](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@adamabelew](https://forum.inductiveautomation.com/u/adamabelew)\
**Post date:** [July 9, 2008, 1:59am UTC](https://forum.inductiveautomation.com/t/fsql-group-execution-error/719/5 "2008-07-09T01:59:21Z")

</div>

Yes I am writing to a column. The type is DATETIME.

I will be onsite tomorrow, and I have a few things to try. I will let you know how I make out…

Thanks,

Adam

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [July 9, 2008, 5:39pm UTC](https://forum.inductiveautomation.com/t/fsql-group-execution-error/719/6 "2008-07-09T17:39:49Z")

</div>

Try setting the action item’s data type to DATE. Sounds like the error may be coming from FactorySQL treating the value as a string.

If you can’t get it to work like that, try setting the type to String, and changing your query to something like the following:

```auto
SELECT Date_Format(TimeDiff(EndTime, BeginTime), '%Y-%m-%e %T') FROM Table WHERE Table_ndx = 10
```

I don’t expect this would be necessary, but basically what it’s doing is having the query return a string that is properly formatted to be sent directly to the database.

Hope this helps,
