Solved

INSERT INTO statement question

Posted on 2014-12-31
7
93 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 65

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 500 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

18 Experts available now in Live!

Get 1:1 Help Now