We help IT Professionals succeed at work.

INSERT INTO statement question

133 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://www.experts-exchange.com/Database/MS-SQL-Server/SQL_Server_2008/Q_28589134.html

Any help is much appreciated.
Comment
Watch Question

Phillip BurtonDirector, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014

Commented:
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 ...
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
<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'.

Author

Commented:
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
Phillip BurtonDirector, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014

Commented:
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

Author

Commented:
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.
Director, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.