[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Why this TSQL syntax error?

Posted on 2011-03-14
4
Medium Priority
?
312 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 1000 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 1000 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 60

Expert Comment

by:HainKurt
ID: 35131874
0
 

Author Closing Comment

by:lapucca
ID: 35132593
Thank you.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

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 …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 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