# SQL Server Scalar Function Works in Client, Fails in GW Tag

**URL:** <https://forum.inductiveautomation.com/t/sql-server-scalar-function-works-in-client-fails-in-gw-tag/8153>\
**Category:** Ignition\
**Created:** [March 14, 2014, 4:44pm UTC](https://forum.inductiveautomation.com/t/sql-server-scalar-function-works-in-client-fails-in-gw-tag/8153 "2014-03-14T16:44:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlangdon](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mlangdon](https://forum.inductiveautomation.com/u/mlangdon)\
**Post date:** [March 14, 2014, 4:44pm UTC](https://forum.inductiveautomation.com/t/sql-server-scalar-function-works-in-client-fails-in-gw-tag/8153/1 "2014-03-14T16:44:35Z")

</div>

I have a SQL function `dbo.machine_availablity()` with a parameter of int  
and a return value of float.

In a Client tag, it returns a number between 0 & 100 as expected. In a gateway tag with identical syntax and parameter, it returns 0. The tag shows good status and there are no generated errors.

Other queries work on Gateway tags; the database connection is fully functional and the SQLTag provider is pointing the correct connection.

Theories? Suggestions?

(Ignition 7.6.4 served by Win 8.1 with SQL Server 2008, designer running on OS X 10.9)

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [March 14, 2014, 5:21pm UTC](https://forum.inductiveautomation.com/t/sql-server-scalar-function-works-in-client-fails-in-gw-tag/8153/2 "2014-03-14T17:21:30Z")

</div>

I tried this with an expression tag and it seems to be working fine for me:

```auto
executeScalarQuery("SELECT dbo.machine_availability(0)", "LocalDB")
```

---

<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:** [March 18, 2014, 5:15pm UTC](https://forum.inductiveautomation.com/t/sql-server-scalar-function-works-in-client-fails-in-gw-tag/8153/3 "2014-03-18T17:15:06Z")

</div>

Hi,

Yes, it’s all a matter of how the query is interpreted… client tags always run them as a “query”, whereas on the gateway, I believe it’s running this as if it were an update… and thus returning 0, for “0 rows updated”.

This has been addressed in 7.7, where you can override the interpretation, but in the mean time, use an expression tag with the function suggested by adamaustin. (Actually, if you can use it with “SELECT …”, it should work in a query tag as well)

Regards,
