I want to randomly select values from one table (1000 rows) and put them in another (4000 rows).
First table is Customer (1000 rows), second table is Customer_Account (4000 rows). They both have a column Customer_ID and Account_ID. In the Customer_Account table, only the Customer_ID column is populated. The Account_ID column of Customer_Account table I want to populate with randomly selected values from the Account_ID column of Customer. This means that the same value from the Customer table may occur multiple times in the Customer_Account table.
This query puts one randomly selected single value from the first table to another 4000 times:
set CustomerID = t2.CustomerID
from Customer_Account t1
cross apply (
select top 10 CustomerID
from Customer
where CustomerID=t1.CustomerId
order by NewID()
) t2
Any suggestions on how I can solve this?
Aucun commentaire:
Enregistrer un commentaire