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 2005 Forums
 Transact-SQL (2005)
 Split table - Scripts

Author  Topic 

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2010-09-07 : 10:29:51
Hi, I have a table with purchased products and each purchased product has a guarantee certificate.
Now, in the new situation people can buy an extra certificate, so this means 1 purchased product can have multiple certificates attached to it.

The table now looks like this (simplified):

PurchasedItems
PurchasedItemID - ProductID - BuyerID - ProductPrice - CertificateID - CertificateStatus - CerificatePrice

Now, I will add a new table called PurchasedItemsCertificates with the fields:
PurchasedItemCertificateID - PurchasedItemID - CertificateID - CertificateStatus - CertificatePrice

And I can alter the PurchasedItems table to:
PurchasedItemID - ProductID - BuyerID - ProductPrice

But is there some way you can make a script to copy the right information to the PurchasedItemsCertificate table?
I don't have any experience with this...

Kristen
Test

22859 Posts

Posted - 2010-09-07 : 14:01:33
[code]INSERT INTO PurchasedItemsCertificates(PurchasedItemID, CertificateID, CertificateStatus, CertificatePrice)
SELECT PurchasedItemID, CertificateID, CertificateStatus, CerificatePrice
FROM PurchasedItems
WHERE CertificateID IS NOT NULL -- Assuming you only want items that HAVE a Certificate
[/code]
Go to Top of Page
   

- Advertisement -