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

INSERT INTO behaviour???

0 views
Skip to first unread message

Burrows

unread,
Nov 20, 2009, 9:58:25 AM11/20/09
to
Hi all I was just writing a quick insert INTO and got an error
Msg 156, Level 15, State 1, Line 15
Incorrect syntax near the keyword 'ORDER'.

INSERT INTO [Test].[dbo].[address1]
(
[ID] ,
[customerId] ,
[line1] ,
[line2]
)
( SELECT
[ID] ,
[customerId] ,
[line1] ,
[line2]
FROM
[dbo].[address]
ORDER BY
[customerId]
)

the funny thing is if I remove the brackets from around the select
statement it works fine any one know why this is the case???

Plamen Ratchev

unread,
Nov 20, 2009, 10:08:52 AM11/20/09
to
The syntax of INSERT...SELECT is without the brackets:
http://msdn.microsoft.com/en-us/library/ms174335.aspx

Also, not sure why you have the ORDER BY, as tables are unordered sets and inserting data in order does not make sense.

--
Plamen Ratchev
http://www.SQLStudio.com

Peso

unread,
Nov 20, 2009, 11:17:55 AM11/20/09
to
Maybe ID column is an IDENTITY, and thus used for "versioning" the entries
from oldest to newest?

//Peter

"Plamen Ratchev" <Pla...@SQLStudio.com> wrote in message
news:sdmdnbACAZlgLZvW...@speakeasy.net...

Plamen Ratchev

unread,
Nov 20, 2009, 11:53:34 AM11/20/09
to
The ID column is included in the INSERT/SELECT list so if IDENTITY in the target table then it is forcing existing
values and ORDER BY has no effect. It will have effect if there is another column in the target table that is IDENTITY.
And sort is by customer id...
0 new messages