SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Why am I getting a T-SQL error near the SELECT verb?


Why am I getting a T-SQL error near the SELECT verb?

Author
Message
sandyshin 42844
sandyshin 42844
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 1
INSERT INTO dbo.mixedwords (Mixed, MixLen, GoodVa)
Values ( SELECT DISTINCT LTRIM(RTRim(mixVa) as NewTerm
, MixCnt
, ValidVal
FROM Sandbox
)
Note: All objects are spelled correctly
The SELECT query runs if highlighted and executed
vulpes
vulpes
Mr or Mrs. 500
Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)

Group: General Forum Members
Points: 594 Visits: 375
Try without Values and the brackets (), after the INSERT INTO line just have the select statement.
Thom A
Thom A
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17879 Visits: 8098
As vulpes said, when using Select in that format, you don't use values. Your SQL should be in the format:
INSERT INTO [DestinationTable] ([List], [of], [Column], [Names])
SELECT [List], [of], [Column], [Names]
FROM [SourceTable]
{WHERE...};





Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does :-P

Please always remember to encapsulate your code in IFCode Markup. For example [code=sql] [/code].
Click here to read Jeffs Guide on how to post SQL questions, and get swift and helpful answers from the community
Ryan Besko
Ryan Besko
SSC Veteran
SSC Veteran (241 reputation)SSC Veteran (241 reputation)SSC Veteran (241 reputation)SSC Veteran (241 reputation)SSC Veteran (241 reputation)SSC Veteran (241 reputation)SSC Veteran (241 reputation)SSC Veteran (241 reputation)

Group: General Forum Members
Points: 241 Visits: 1628
sandyshin 42844 - Sunday, July 16, 2017 8:22 PM
INSERT INTO dbo.mixedwords (Mixed, MixLen, GoodVa)
Values ( SELECT DISTINCT LTRIM(RTRim(mixVa) as NewTerm
, MixCnt
, ValidVal
FROM Sandbox
)
Note: All objects are spelled correctly
The SELECT query runs if highlighted and executed

A missing closing parenthesis here, too: LTRIM(RTRim(mixVa)
Not sure how it would still run if you just highlighted it and executed it.

Anjan@Sql
Anjan@Sql
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1250 Visits: 1498

INSERT INTO dbo.mixedwords (Mixed, MixLen, GoodVa)

SELECT DISTINCT LTRIM(RTRim(mixVa)) as NewTerm

, MixCnt

, ValidVal

FROM Sandbox


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search