Solved

Insert single column into table using select statement

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tempdb log keep growing 7 33
Download ms sql express. 2 26
SQL Server 2008 R2, need a pivot/cross tab query... 4 28
query linked sql table field from access 4 21
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

856 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