Solved

Insert single column into table using select statement

Posted on 2006-07-17
2
1,489 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

911 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