Reputation: 35
My issue with an old customer plus outdated system.Part of issue. The 3 tables contain existing data in database. Let me explain, what was the scenario and then I hope you guys can help me get this job done.
Scenario :
Explanation :
If i understand correctly i have to massive insert ProductZone and in this case by complicate T-SQL both filter condition and insert statement.
I'd be glad to take any suggestions,Thanks in advance.
Upvotes: 2
Views: 175
Reputation: 20745
This query will populate the Zones for existing products available in ProductZone Table and the new products available in Product table.
INSERT INTO ProductZone
SELECT ZoneNo,
ProductNo
FROM Product a
CROSS JOIN ZONE b
WHERE NOT EXISTS (SELECT 1
FROM ProductZone c
WHERE a.ProductNo = c.ProductNo
AND a.zone = c.zone)
Upvotes: 1