Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

INSERT INTO statement question

Posted on 2014-12-31
7
Medium Priority
?
119 Views
Last Modified: 2015-01-14
Hello, question about INSERT INTO statement.  Is it possible to use insert into statement with SELECT to copy data from one column to a new column in MS SQL?  I am including a link to a related question I have for the experts.

https://secure.experts-exchange.com/Database/MS-SQL-Server/SQL_Server_2008/Q_28589134.html

Any help is much appreciated.
0
Comment
Question by:blackcatkempo
  • 3
  • 3
7 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40526027
INSERT INTO does not copy from one column to another in existing columns, It inserts extra rows.

It sounds like what you want is
UPDATE tablename
SET column1 = column2
WHERE ...
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40526128
<somewhat redundant with the above post>

INSERT adds new rows to a table, either by using a SELECT statement, or entering VALUES.
UPDATE modifies existing rows in a table.

So ... give us a data mockup of exactly what you are trying to pull off here, with better definition of 'one column' and 'new column'.
0
 

Author Comment

by:blackcatkempo
ID: 40527656
I would like to populate a new column labeled "hostname", which is DNS resolution of the host column.  The hostname column should only have hostnames per row.  The hostname can be found in the [plugin output] column for each row.  To find the correct row aligning with correct [plugin output] (hostname); the row will have a [plugin id] labeled - 55472.  Attached is sample data file.
28589163SAMPLE-DATA3.csv
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40527659
I can't see many of those in the "Plugin Output"; it seems to contain mostly everything else.

Also, most of them include multiple DNS addresses, e.g.

 For your information, here is the traceroute from 172.16.24.62 to 172.16.24.63 :

172.16.2.35
172.16.2.34
172.16.3.23
172.16.4.25
192.168.1.28
192.168.2.6
0
 

Author Comment

by:blackcatkempo
ID: 40527684
Yes the traceroute is accurate, but its not a one-to-one mapping. The sample file I attached unfortunately only has a single hostname to ip mapping. The full table (not attached) lists 10K hosts each with a mapped hostname using Plugin Id - 55472.  I need the code to copy the hostname from plugin output column to a new column labeled "hostname".  Having a dedicated column with mapped hostname will help immensely.
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40527685
Then you use the

UPDATE tablename
SET column1 = column2
WHERE ...

Without any additional information, that's the best that can be made.

Basically, get your SELECT statement with all of the joins, then add the first two lines above on.
0
 

Author Comment

by:blackcatkempo
ID: 40529720
Thank you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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