Solved

INSERT INTO statement question

Posted on 2014-12-31
7
99 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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