Solved

Insert single column into table using select statement

Posted on 2006-07-17
2
1,479 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
2 Comments
 
LVL 25

Accepted Solution

by:
Mr_Peerapol earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now