# Order by problem

**URL:** <https://forum.inductiveautomation.com/t/order-by-problem/3528>\
**Category:** Ignition\
**Created:** [October 31, 2011, 4:54pm UTC](https://forum.inductiveautomation.com/t/order-by-problem/3528 "2011-10-31T16:54:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WEControl](https://avatars.discourse-cdn.com/v4/letter/w/f14d63/32.png) [@WEControl](https://forum.inductiveautomation.com/u/WEControl)\
**Post date:** [October 31, 2011, 4:54pm UTC](https://forum.inductiveautomation.com/t/order-by-problem/3528/1 "2011-10-31T16:54:57Z")

</div>

When I make a table and under the SQL Query and put in ORDER BY then whatever ASC and hit ok I always get this error.

Exception: Error running query:  
SQLQuery(query=SELECT ID, Name, Address, Phone FROM Customers2  
WHERE Name LIKE ‘%%’  
ORDER BY Name ASC, database=WEDatabase)@0ms  
On: Search Test.Root Container.Table.data  
caused by GatewayException: The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.  
caused by SQLServerException: The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

Ignition v7.3.1 (b496)  
Java: Sun Microsystems Inc. 1.6.0\_29

Not quite sure what to do to fix it.

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [October 31, 2011, 5:29pm UTC](https://forum.inductiveautomation.com/t/order-by-problem/3528/2 "2011-10-31T17:29:13Z")

</div>

Sorting on “LIKE”'d fields with wildcards can be finicky with data types depending on the flavor of SQL.

Try this query:

```auto
SELECT ID, Name, Address, Phone FROM Customers2 WHERE Name LIKE '%' ORDER BY cast(Name as varchar(500)) ASC
```

The logic is that % can match null, but you can’t sort null so the interpreter throws an error.

EDIT: You are successfully running Java 6 with the 29 update? How is that working for you?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [October 31, 2011, 5:29pm UTC](https://forum.inductiveautomation.com/t/order-by-problem/3528/3 "2011-10-31T17:29:34Z")

</div>

Which database are you using (MySQL, MS SQL Server)?

---

<div class="post-metadata">

**Author:** ![WEControl](https://avatars.discourse-cdn.com/v4/letter/w/f14d63/32.png) [@WEControl](https://forum.inductiveautomation.com/u/WEControl)\
**Post date:** [October 31, 2011, 5:42pm UTC](https://forum.inductiveautomation.com/t/order-by-problem/3528/4 "2011-10-31T17:42:23Z")

</div>

It is a MS SQL Server. Your code worked gbuehler thanks!
