Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Incorrect syntax near the keyword 'ORDER'.

990 views
Skip to first unread message

blindsey

unread,
Feb 25, 2008, 10:34:58 PM2/25/08
to
I'm getting this error message:

Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'ORDER'.

For this statement:

INSERT INTO TEMP_BOOKING2 (PRISONER_ID,BOOKING_NO,
SENT_EFF_DATE1,SYSID)
(SELECT PRISONER_ID,BOOKING_NO,SENT_EFF_DATE,ROWNO
FROM TEMP_BOOKING
ORDER BY PRISONER_ID,SENT_EFF_DATE);

(It works when I take out the ORDER BY clause, but I need that for an
identity column on the target table.)

Jesse Hersch

unread,
Feb 25, 2008, 10:48:16 PM2/25/08
to
if you want to explicity specify the values for an identity column, you have
to do this:

set identity_insert MyTable on
-- do the insert
set identity_insert MyTable off

see BOL for details on identity_insert

--
http://elsasoft.org

"blindsey" <blin...@dsicdi.com> wrote in message
news:104c804e-d87a-47ae...@u69g2000hse.googlegroups.com...

Tom Cooper

unread,
Feb 26, 2008, 1:03:09 AM2/26/08
to
Remove the parenthesis around the select clause.

INSERT INTO TEMP_BOOKING2 (PRISONER_ID,BOOKING_NO,
SENT_EFF_DATE1,SYSID)

SELECT PRISONER_ID,BOOKING_NO,SENT_EFF_DATE,ROWNO
FROM TEMP_BOOKING
ORDER BY PRISONER_ID,SENT_EFF_DATE;

Tom

"blindsey" <blin...@dsicdi.com> wrote in message
news:104c804e-d87a-47ae...@u69g2000hse.googlegroups.com...

David Portas

unread,
Feb 26, 2008, 1:19:49 AM2/26/08
to
"blindsey" <blin...@dsicdi.com> wrote in message
news:104c804e-d87a-47ae...@u69g2000hse.googlegroups.com...


Remove the second set of parentheses.

Don't use ORDER BY as part of an INSERT statement. It achieves nothing
useful because tables are always unordered.

--
David Portas


0 new messages