Advertisement
Teammasik

laba_3_BD_procedures+def

Oct 12th, 2023 (edited)
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.74 KB | None | 0 0
  1. --1
  2. create or alter procedure CoopCity
  3. @InCity varchar(30)
  4. as
  5. select Cooperator.Name, Surname, Cooperator.City
  6. from Cooperator
  7. join Company on Cooperator.City = Company.City and Company.City = @InCity
  8. join Department on Department.Dept_id = Cooperator.Dept_id and Department.Company_id = Company.Company_id
  9.  
  10. exec [CoopCity] 'Сургут'
  11.  
  12. --2
  13. create or alter procedure QuantCoopCateg
  14. @InCategory varchar(30)
  15. as
  16. select Count(*) as 'Количество', @InCategory as 'Категория'
  17. from Cooperator
  18. where Cooperator.Category = @InCategory
  19.  
  20. exec [QuantCoopCateg] 'Инженер'
  21.  
  22. --3
  23. create or alter procedure CoopSalary
  24. @InSalary int=0
  25. as
  26. select Count(*) 'Количество', @InSalary 'Зарплата'
  27. from Cooperator
  28. where Cooperator.Salary > @InSalary
  29.  
  30. exec [CoopSalary] 80000
  31.  
  32. --4
  33. create or alter procedure CoopCompanyName
  34. @InCompName varchar(30)
  35. as
  36. select Cooperator.Name 'Имя', Cooperator.Surname 'Фамилия', @InCompName 'Название'
  37. from Cooperator, Department, Company
  38. where Department.Dept_id = Cooperator.Dept_id and Company.Company_id = Department.Company_id and Company.Name = @InCompName
  39.  
  40. exec [CoopCompanyName] 'ПАО АНК Башнефть'
  41.  
  42. --5
  43. create or alter procedure IncreaseSalaryByEval
  44. @InPercentInc int, @InStatus  decimal
  45. AS
  46. update Cooperator
  47. set Salary = Salary*(100+@InPercentInc)/100
  48. where Cooperator.Cooperator_id in (
  49. SELECT Cooperator.Cooperator_id
  50. FROM Cooperator, Evaluation, (SELECT Evaluation.DATE, Cooperator.Cooperator_id
  51.                                 FROM Cooperator, Evaluation
  52.                                 WHERE Cooperator.Cooperator_id = Evaluation.Cooperator_id) t
  53. WHERE Cooperator.Cooperator_id = t.Cooperator_id AND  Evaluation.STATUS >= @InStatus
  54. GROUP BY Cooperator.Cooperator_id,Evaluation.DATE
  55. HAVING Evaluation.DATE = MAX(t.DATE)
  56. )
  57.  
  58. exec [IncreaseSalaryByEval] 5,5
  59.  
  60. --6
  61. exec sp_helptext 'IncreaseSalaryByEval'
  62.  
  63. --zashita
  64. /*
  65. создать процедуру которая будет уменьшать зп если у этого сотрудника последняя оценка 3
  66. уменьшает на процент при вызове процедуры
  67. */
  68.  
  69. create or alter procedure decPerc
  70. @InPerc int
  71. as
  72. update Cooperator
  73. set Salary = Salary*(100-@InPerc)/100
  74. where Cooperator.Cooperator_id in (
  75.     SELECT Cooperator.Cooperator_id
  76.     FROM Cooperator, Evaluation, (SELECT Evaluation.DATE, Cooperator.Cooperator_id, Evaluation.Status
  77.                                     FROM Cooperator, Evaluation
  78.                                     WHERE Cooperator.Cooperator_id = Evaluation.Cooperator_id) t
  79.     WHERE Cooperator.Cooperator_id = t.Cooperator_id AND  Evaluation.STATUS = 3
  80.     GROUP BY Cooperator.Cooperator_id,Evaluation.DATE
  81.     HAVING Evaluation.DATE = MAX(t.DATE))
  82.  
  83. exec decPerc 10
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement