Guest User

Untitled

a guest
Jan 22nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. DELIMITER $$
  2. DROP PROCEDURE IF EXISTS InsertProductLinks$$
  3. CREATE PROCEDURE InsertProductLinks()
  4. BEGIN
  5. DECLARE min_pg INT;
  6. DECLARE max_pg INT;
  7. DECLARE pg INT;
  8. DECLARE cat INT;
  9. SELECT min_pg = min(id), max_pg = max(id) FROM product_landing_pages;
  10. SELECT pg = min_pg, cat = pn_category_id FROM product_landing_pages WHERE id = min_pg;
  11. WHILE pg <= max_pg
  12. /* get next category # */
  13. select cat = pn_category_id from product_landing_pages where id = pg;
  14. /* delete existing records/parts per current category */
  15. delete apto...part_number_landing_links where pn_category_id = @cat;
  16. /* insert 4 random parts per current category */
  17. insert into apto...part_number_landing_links(part_number_id, product_landing_page_id, pn_category_id);
  18. select pn.id as part_number_id, pg as product_landing_page_id, cat as pn_category_id from product_price_upd
  19. join part_cat
  20. on partnumber = part_cat.part
  21. and mfgcode = part_cat.line
  22. join pn_categories
  23. on left(grp, 45) = left(name, 45)
  24. and pn_categories.id = @cat
  25. join part_numbers pn
  26. on part_cat.line = line_code
  27. and part = pn.number;
  28. where qty_available > 0
  29. /* increment page # */
  30. set @pg = @pg+1;
  31. END WHILE;
  32. END$$
  33. DELIMITER;
Add Comment
Please, Sign In to add comment