Solved

INSERT INTO statement question

Posted on 2014-12-31
7
109 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

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.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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