---
title: "Syntax error near the keyword order [on hold] in SQL Server"  
description: "Syntax error near the keyword order [on hold] in SQL Server"  
author: "Manoj Bhatt"  
published: 2014-09-22  
updated: 2023-04-28  
canonical: https://www.mindstick.com/forum/2267/syntax-error-near-the-keyword-order-on-hold-in-sql-server  
category: "database"  
tags: ["database"]  
reading_time: 3 minutes  

---

# Syntax error near the keyword order [on hold] in SQL Server

When I [execute](https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line) this [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver):

```
SELECT    orders.id, orders.order - time, orders.pizza.id,    orders.pizza.type, orders.pizza-size, orders.quantity, FROM    orders INNER JOIN    permit ON orders.id = pizza.id WHERE   
([username] =
@username)
```

I got an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net):

[Syntax error](https://www.mindstick.com/forum/159599/what-is-a-syntax-error-in-sql-give-an-example) near the [keyword](https://www.mindstick.com/forum/33572/sql-inner-join-keyword) [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience)

Any clue how to solve this?

## Replies

### Reply by Aryan Kumar

The error "Syntax error near the keyword order" in SQL Server usually occurs when there is a syntax error in your SQL statement involving the "ORDER BY" clause.

Here are some possible causes and solutions:

1. **Incorrect syntax:** Make sure that you have spelled the "ORDER BY" clause correctly and that it appears in the correct location within the SQL statement. For example, if you are using a SELECT statement, the ORDER BY clause should appear at the end of the statement after the WHERE clause (if present) and before any GROUP BY or HAVING clauses.
2. **Missing or extra punctuation:** Check for missing or extra punctuation marks such as commas, parentheses, or semicolons in your SQL statement. These can cause syntax errors that prevent the statement from executing properly.
3. **Incorrect data types:** Make sure that the data types of the columns being ordered match the data types specified in the ORDER BY clause. For example, if you are ordering a column of dates, make sure that the column is of the date data type and that you are using the correct date format in the ORDER BY clause.
4. **Reserved keywords:** Avoid using reserved keywords such as "ORDER" or "GROUP" as column names or aliases, as this can cause syntax errors. If you must use a reserved keyword, enclose the column name or alias in brackets [].

Here's an example of a correct syntax for an ORDER BY clause:

```php
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column1 ASC/DESC, column2 ASC/DESC, ...;
```

Make sure that your SQL statement follows this format and that there are no syntax errors or punctuation mistakes.

### Reply by Anchal Kesharwani

hi manoj,

I hope that this is helpful for you.

Since you have no **order by** clause and the [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) message is complaining about your statement near the **order** keyword, I explain that there are two possibilities.

The first is that you've left the s of one of your table specifiers, using order instead of orders, despite your transcription.

The second is that **orders.order-time** is incorrect, being treated as **orders.order - time**. In fact, I'd be a little worried by many of your names, including those that have two periods (.) in them. You may want to check if the - and the subsequent . characters should be underscores (_) instead.

You also have a trailing comma after the last column selection (before the from), which is not valid SQL.


---

Original Source: https://www.mindstick.com/forum/2267/syntax-error-near-the-keyword-order-on-hold-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
