Solved

SQL Populate a table with its own data but change a field

Posted on 2013-02-01
3
182 Views
Last Modified: 2013-02-01
Hi

I have a table Table1 that contains a CompanyID column.
What SQL would I use to Select * From the Table and Add it back to the
table with a different Company ID
0
Comment
Question by:murbro
3 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 250 total points
ID: 38842969
you should perform an update normally

UPDATE Table1 SET CompanyId = YourNewCompanyId

e.g

UPDATE Table1 SET CompanyId = 56


if you only want to change certain records, you can use a WHERE clause with that

e.g

UPDATE Table1 SET CompanyId = 56 WHERE CompanyId  = 99
0
 
LVL 23

Assisted Solution

by:Ioannis Paraskevopoulos
Ioannis Paraskevopoulos earned 250 total points
ID: 38842981
Hi,

If your intention is to add the same data for another company then do the following

DECLARE @NewCompanyID AS INT
SET @NewCompanyID = 2 --or whatever is your new company id
INSERT INTO Table1
SELECT @NewCompanyID,
            Col2,
            Col3,
            .
            .
            .
            Coln
FROM   Table1
WHERE  CompanyId = 1 --provided that 1 is the company id that it is already in that table

Open in new window


Giannis
0
 

Author Closing Comment

by:murbro
ID: 38843310
Thanks for the help
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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

749 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