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
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 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
SSChasing Mays
SSChasing Mays (647 reputation)SSChasing Mays (647 reputation)SSChasing Mays (647 reputation)SSChasing Mays (647 reputation)SSChasing Mays (647 reputation)SSChasing Mays (647 reputation)SSChasing Mays (647 reputation)SSChasing Mays (647 reputation)

Group: General Forum Members
Points: 647 Visits: 389
Try without Values and the brackets (), after the INSERT INTO line just have the select statement.
Thom A
Thom A
SSC-Forever
SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)

Group: General Forum Members
Points: 46220 Visits: 15719
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
Mr or Mrs. 500
Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)

Group: General Forum Members
Points: 565 Visits: 2693
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
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1594 Visits: 1572

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