Guest User

Untitled

a guest
Dec 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. IF object_id('sp_SuaSuatChieu', 'p') is not null
  2. DROP PROC sp_SuaSuatChieu
  3. go
  4. --Procedure sửa suất chiếu: nhận vào idsuatchieu,idphong mới, ngay mới, thời gian bắt đầu mới, iddingdang mới, loaive mới
  5. --Thực hiện tạo mới suất chiếu và thêm vé của suất chiếu đó vào bảng vé
  6. create procedure sp_SuaSuatChieu @idsuatchieu int, @idphongmoi int, @ngaymoi date, @thoigianbdmoi time, @iddinhdangmoi char(2)
  7. as
  8. begin tran
  9. set tran isolation level repeatable read
  10. begin try
  11. --Thay đổi ngày mới
  12. if (@ngaymoi is not null)
  13. begin
  14. update SuatChieu
  15. set ngay = @ngaymoi
  16. where idsuatchieu = @idsuatchieu
  17.  
  18. if(DATEDIFF(day,getdate(),@ngaymoi)>3 or DATEDIFF(day,getdate(),@ngaymoi)<1)
  19. begin
  20. rollback tran
  21. end
  22. end
  23. --Thay đổi thời gian bắt đầu mới
  24. if(@thoigianbdmoi is not null)
  25. begin
  26. update SuatChieu
  27. set thoigianbd= @thoigianbdmoi
  28. where idsuatchieu = @idsuatchieu
  29. end
  30. --Thay đổi định dạng mới
  31. if(@iddinhdangmoi is not null)
  32. begin
  33. update SuatChieu
  34. set iddinhdang= @iddinhdangmoi
  35. where idsuatchieu = @idsuatchieu
  36. end
  37. --Thay đổi phòng mới
  38. if(@idphongmoi is not null)
  39. begin
  40. update SuatChieu
  41. set idphong = @idphongmoi
  42. where idsuatchieu = @idsuatchieu
  43.  
  44. declare @BangVe table(idVe int NOT NULL)
  45. declare @BangGhe table(idGhe int NOT NULL)
  46. insert into @BangVe(idVe)
  47. select idve
  48. from Ve
  49. where suat = @idsuatchieu
  50.  
  51. insert into @BangGhe(idGhe)
  52. select idghe
  53. from Ghe
  54. where idphong = @idphongmoi
  55.  
  56. declare @idghe int
  57. declare @idve int
  58. while exists (select 1 from @BangGhe)
  59. begin
  60. select top (1) @idghe = idGhe from @BangGhe
  61. select top (1) @idve = idVe from @BangVe
  62. update Ve
  63. set ghe = @idghe
  64. from Ve v
  65. where v.idve = @idve
  66.  
  67. delete top(1)
  68. from @BangGhe
  69. delete top(1)
  70. from @BangVe
  71. end
  72. end
  73. end try
  74. begin catch
  75. select ERROR_MESSAGE() as ErrorMassage
  76. rollback tran
  77. end catch
  78. commit tran
Add Comment
Please, Sign In to add comment