Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Inserting copies of products under different compa

Author  Topic 

goofy78270
Starting Member

4 Posts

Posted - 2011-06-13 : 16:48:08
I have a db in which a company has over 100 products that we use. The company recently changed names and now I need to reinput the product list for the new company. Is there a simple way to "copy" all the products from company A and insert them as company B?

Regards,
Mike

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-13 : 16:56:38
Can't you just update the pointers? And why isn't the company name easily updateable so that it's metadata of say an identity column?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

goofy78270
Starting Member

4 Posts

Posted - 2011-06-13 : 18:38:30
We would like to keep the old company A and Company B seperate for historic purposes as we add and remove products frequently. I doing so, I would need to recreate all the products currently under company A, under company B. I was looking for a simple sql script to accomplish this.

Regards,
Mike
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-13 : 18:47:13
While we can help you write the script to do this, you'll need to provide more information as there is no built-in or custom script out there that can handle your specific database design.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

goofy78270
Starting Member

4 Posts

Posted - 2011-06-14 : 11:12:01
I am unsure what information you need other than a table layout, so here you go.

Product Table design:

PIdx
Company Idx
PCode
PName
PDescription
PHeight
PLength
PWidth
PPrice


I was thinking about loading the values for all products from company A (Company Idx 6) into a temp table and then inserting those values back into the product table while changing the Company Idx to 9, but I am unsure exactly how to write something like this.

Regards,
Mike
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-06-14 : 12:35:18
Should just be a simpe insert statement. Something like:
INSERT
dbo.Product
(
CompanyIdx,
PCode,
PName,
PDescription,
PHeight,
PLength,
PWidth,
PPrice

)
SELECT
9,
PCode,
PName,
PDescription,
PHeight,
PLength,
PWidth,
PPrice
FROM
dbo.Product
WHERE
CompanyIdx = 6
Go to Top of Page
   

- Advertisement -