Solved

Why this TSQL syntax error?

Posted on 2011-03-14
4
310 Views
Last Modified: 2012-05-11
Hi, I'm using sql 2005 express.  The sub select query runs fine when I run it by itself.  But I got the following error when I embedded it in this Insert error?  Thanks.

INSERT INTO [MedDb].[dbo].[DegreeMajor]
           ([Major Title])
     VALUES
           (select distinct degree_Major from dbo.PersonDegree pd
                  where degree_Major is not null and degree_Major <> '.' and degree_Major <> '')


Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ')'.
0
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 12

Accepted Solution

by:
enachemc earned 250 total points
ID: 35131825
INSERT INTO [MedDb].[dbo].[DegreeMajor]
           ([Major Title])
           select distinct degree_Major from dbo.PersonDegree pd
                  where degree_Major is not null and degree_Major <> '.' and degree_Major <> ''


do not use values
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 250 total points
ID: 35131871
try :
INSERT INTO [MedDb].[dbo].[DegreeMajor]
           ([Major Title])
           select distinct degree_Major from dbo.PersonDegree pd
                  where degree_Major is not null and degree_Major <> '.' and degree_Major <> '')

When using a subselect for an insert into you don't use the values keyword.
These are the valid statements :

Insert Into <table name>(<column name>) values(<set of values>)

or

Insert Into <table name>(<column name>) Select <Set of values> or <local variables> From <table name>


0
 
LVL 55

Expert Comment

by:Huseyin KAHRAMAN
ID: 35131874
0
 

Author Closing Comment

by:lapucca
ID: 35132593
Thank you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question