Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IF object_id('sp_SuaSuatChieu', 'p') is not null
- DROP PROC sp_SuaSuatChieu
- go
- --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
- --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é
- create procedure sp_SuaSuatChieu @idsuatchieu int, @idphongmoi int, @ngaymoi date, @thoigianbdmoi time, @iddinhdangmoi char(2)
- as
- begin tran
- set tran isolation level repeatable read
- begin try
- --Thay đổi ngày mới
- if (@ngaymoi is not null)
- begin
- update SuatChieu
- set ngay = @ngaymoi
- where idsuatchieu = @idsuatchieu
- if(DATEDIFF(day,getdate(),@ngaymoi)>3 or DATEDIFF(day,getdate(),@ngaymoi)<1)
- begin
- rollback tran
- end
- end
- --Thay đổi thời gian bắt đầu mới
- if(@thoigianbdmoi is not null)
- begin
- update SuatChieu
- set thoigianbd= @thoigianbdmoi
- where idsuatchieu = @idsuatchieu
- end
- --Thay đổi định dạng mới
- if(@iddinhdangmoi is not null)
- begin
- update SuatChieu
- set iddinhdang= @iddinhdangmoi
- where idsuatchieu = @idsuatchieu
- end
- --Thay đổi phòng mới
- if(@idphongmoi is not null)
- begin
- update SuatChieu
- set idphong = @idphongmoi
- where idsuatchieu = @idsuatchieu
- declare @BangVe table(idVe int NOT NULL)
- declare @BangGhe table(idGhe int NOT NULL)
- insert into @BangVe(idVe)
- select idve
- from Ve
- where suat = @idsuatchieu
- insert into @BangGhe(idGhe)
- select idghe
- from Ghe
- where idphong = @idphongmoi
- declare @idghe int
- declare @idve int
- while exists (select 1 from @BangGhe)
- begin
- select top (1) @idghe = idGhe from @BangGhe
- select top (1) @idve = idVe from @BangVe
- update Ve
- set ghe = @idghe
- from Ve v
- where v.idve = @idve
- delete top(1)
- from @BangGhe
- delete top(1)
- from @BangVe
- end
- end
- end try
- begin catch
- select ERROR_MESSAGE() as ErrorMassage
- rollback tran
- end catch
- commit tran
Add Comment
Please, Sign In to add comment