• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

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

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
Murray Brown
Asked:
Murray Brown
2 Solutions
 
deightonCommented:
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
 
Ioannis ParaskevopoulosCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now