Advertisement
mayankjoin3

generateTable - Procedure - Balbeer

Oct 5th, 2022
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.96 KB | None | 0 0
  1. BEGIN
  2. DECLARE n INT DEFAULT 0;
  3. DECLARE i INT DEFAULT 0;
  4. DECLARE j INT DEFAULT 0;
  5. DECLARE m INT DEFAULT 0;
  6. DECLARE iv INT DEFAULT 0;
  7. DECLARE hv TEXT;
  8. DECLARE ov TEXT;
  9. DECLARE rv TEXT;
  10. DECLARE nm1 TEXT;
  11. DECLARE nm2 TEXT;
  12. DECLARE r1 TEXT;
  13. DECLARE r2 TEXT;
  14. DECLARE pg1 TEXT;
  15. DECLARE pg2 TEXT;
  16. DECLARE eml1 TEXT;
  17. DECLARE eml2 TEXT;
  18. DECLARE mb1 TEXT;
  19. DECLARE mb2 TEXT;
  20. DECLARE g1 TEXT;
  21. DECLARE g2 TEXT;
  22. DECLARE nm3 TEXT;
  23. DECLARE r3 TEXT;
  24. DECLARE pg3 TEXT;
  25. DECLARE eml3 TEXT;
  26. DECLARE mb3 TEXT;
  27. DECLARE g3 TEXT;
  28. DECLARE fr TEXT;
  29. DECLARE cr TEXT;
  30. DECLARE hos TEXT;
  31. SELECT COUNT(*) FROM mess_master_room_mapping INTO n;
  32. DROP TABLE IF EXISTS mess_room_occupancy;
  33. CREATE TABLE `mess_room_occupancy` (
  34.   `hostel` text DEFAULT NULL,
  35.   `room` text DEFAULT NULL,
  36.   `capacity` text DEFAULT NULL,
  37.   `occupied` text DEFAULT NULL,
  38.   `free` text DEFAULT NULL,
  39.   `roll1` text DEFAULT NULL,
  40.   `name1` text DEFAULT NULL,
  41.   `mobile1` text DEFAULT NULL,
  42.   `prog1` text DEFAULT NULL,
  43.   `mail1` text DEFAULT NULL,
  44.   `gender1` text DEFAULT NULL,
  45.   `roll2` text DEFAULT NULL,
  46.   `name2` text DEFAULT NULL,
  47.   `mobile2` text DEFAULT NULL,
  48.   `prog2` text DEFAULT NULL,
  49.   `mail2` text DEFAULT NULL,
  50.   `gender2` text DEFAULT NULL,
  51.   `roll3` text DEFAULT NULL,
  52.   `name3` text DEFAULT NULL,
  53.   `mobile3` text DEFAULT NULL,
  54.   `prog3` text DEFAULT NULL,
  55.   `mail3` text DEFAULT NULL,
  56.   `gender3` text DEFAULT NULL
  57. );
  58. SET i=0;
  59. WHILE i<n
  60. DO
  61.   SELECT id, hostel ,occupancy , room FROM mess_master_room_mapping LIMIT i , 1 INTO iv , hv , ov , rv ;
  62.   SET i = i + 1;
  63.   SET hos = CONCAT(hv,'%');
  64.   SELECT COUNT(*) FROM mess_student_hostel_hostelinfo WHERE hostel_full_room = rv and hostel_name LIKE hos INTO m;
  65.   IF m = 3 THEN
  66.     SELECT name , rollno , mobile , email , prog , gender FROM mess_student_hostel_hostelinfo WHERE hostel_full_room = rv and hostel_name LIKE hos LIMIT 0 , 1 INTO nm1 , r1 , mb1 , eml1 , pg1 , g1 ;
  67.     SELECT name , rollno , mobile , email , prog , gender FROM mess_student_hostel_hostelinfo WHERE hostel_full_room = rv and hostel_name LIKE hos LIMIT 1 , 1 INTO nm2 , r2 , mb2 , eml2 , pg2 , g2 ;
  68.     SELECT name , rollno , mobile , email , prog , gender FROM mess_student_hostel_hostelinfo WHERE hostel_full_room = rv and hostel_name LIKE hos LIMIT 2 , 1 INTO nm3 , r3 , mb3 , eml3 , pg3 , g3 ;
  69.     INSERT INTO mess_room_occupancy ( hostel , room , capacity , occupied , free , roll1 , name1 , mobile1 , mail1 , prog1 , gender1 , roll2 , name2 , mobile2 , mail2 , prog2 , gender2 , roll3 , name3 , mobile3 , mail3 , prog3 , gender3)
  70.     VALUES ( hv , rv , ov , 3 , (ov-3) , r1 , nm1 , mb1 , eml1 , pg1 , g1 , r2 , nm2 , mb2 , eml2 , pg2 , g2 , r3 , nm3 , mb3 , eml3 , pg3 , g3  );
  71.   ELSEIF m = 2 THEN
  72.     SELECT name , rollno , mobile , email , prog , gender FROM mess_student_hostel_hostelinfo WHERE hostel_full_room = rv and hostel_name LIKE hos LIMIT 0 , 1 INTO nm1 , r1 , mb1 , eml1 , pg1 , g1  ;
  73.     SELECT name , rollno , mobile , email , prog , gender FROM mess_student_hostel_hostelinfo WHERE hostel_full_room = rv and hostel_name LIKE hos LIMIT 1 , 1 INTO nm2 , r2 , mb2 , eml2 , pg2 , g2 ;
  74.     INSERT INTO mess_room_occupancy ( hostel , room , capacity , occupied , free , roll1 , name1 , mobile1 , mail1 , prog1 , gender1 , roll2 , name2 , mobile2 , mail2 , prog2 , gender2 )
  75.     VALUES ( hv , rv , ov , 2 , (ov-2) ,  r1 , nm1 , mb1 , eml1 , pg1 , g1 , r2 , nm2 , mb2 , eml2 , pg2 , g2 );
  76.   ELSEIF m=1 THEN
  77.     SELECT name , rollno , mobile , email , prog , gender FROM mess_student_hostel_hostelinfo WHERE hostel_full_room = rv and hostel_name LIKE hos LIMIT 0 , 1 INTO nm1 , r1 , mb1 , eml1 , pg1 , g1 ;
  78.     INSERT INTO mess_room_occupancy ( hostel , room , capacity , occupied , free , roll1 , name1 , mobile1 , mail1 , prog1 , gender1 )
  79.     VALUES ( hv , rv , ov , 1 , (ov-1) , r1 , nm1 , mb1 , eml1 , pg1 , g1  );
  80.   ELSE
  81.     INSERT INTO mess_room_occupancy ( hostel , room , capacity , occupied , free )
  82.     VALUES ( hv , rv , ov , 0 , ov  );
  83.   END IF;
  84.  
  85. END WHILE;
  86. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement