Solved

Automatically create an insert statement based on values in a table.

Posted on 2016-09-14
3
66 Views
Last Modified: 2016-09-28
I have a test table with values inserted into it.  I want to create and insert statement to insert all the values into a production statement based on what is in test. Is there any easy way to create the statement?
0
Comment
Question by:vbnetcoder
[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
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41798098
In the Production SQL Server instance create a Linked Server for the Test MSSQL instance and run the following in the Production database:
USE ProdDB
GO
INSERT INTO TableName (Col1Name, Col2Name, ..., ColnName)
SELECT (Col1Name, Col2Name, ..., ColnName)
FROM TestLinkedServer.TestDB.dbo.Tablename

Open in new window

0
 
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 41820016
vbnetcoder, any feedback will be appreciated.
0
 

Author Closing Comment

by:vbnetcoder
ID: 41820058
That helps -- thank you.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

690 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