Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Insert single column into table using select statement

Posted on 2006-07-17
2
Medium Priority
?
1,524 Views
Last Modified: 2010-05-18
Hello everyone,

I have a table with over 10 columns.  I want to insert data into only one of the column using data from another column.  My SQL looks  like this, but it's not working.

INSERT INTO dbo.dcx_dealer_code (Dealer_Code) Values
(select distinct detail.Dealer_Code from dbo.dcx_warranty_detail_report detail
LEFT OUTER JOIN dbo.dcx_dealer_code dcode ON
dcode.Dealer_Code = detail.Dealer_Code
WHERE dcode.Dealer_Code is null)

I have done this before, but the destination columns always matched the source columns, this time I can't figure this out.  Any prompt help will be much appreciated.

0
Comment
Question by:tomasz_k
[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
2 Comments
 
LVL 25

Accepted Solution

by:
Mr_Peerapol earned 2000 total points
ID: 17121955
Try this:

INSERT INTO dbo.dcx_dealer_code (Dealer_Code)
(select distinct detail.Dealer_Code from dbo.dcx_warranty_detail_report detail
LEFT OUTER JOIN dbo.dcx_dealer_code dcode ON
dcode.Dealer_Code = detail.Dealer_Code
WHERE dcode.Dealer_Code is null)
0
 

Author Comment

by:tomasz_k
ID: 17121967
Worked like a charm...too bad I haven't came up with that :( Thanks.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

648 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