Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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