Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.80 KB | None | 0 0
  1. If OBJECT_ID('usp_Cau11','p') is not null
  2.     drop proc usp_Cau11
  3. go
  4. create proc usp_Cau11
  5. @mapm char(10),
  6. @ngaymuon date
  7. as
  8.     if not exists(select * from PhieuMuon where mapm= @mapm) return 1
  9.    
  10.     Update PhieuMuon
  11.     set ngaymuon = @ngaymuon
  12.     where mapm= @mapm
  13.  
  14.     update ctpt
  15.     set tienphat =
  16.          IIF(ctpt.mucgiaphat*(DATEDIFF(DD,pm.ngaymuon, pt.ngaytra)-ctpm.songayquydinh)>=0,ctpt.mucgiaphat*(DATEDIFF(DD,pm.ngaymuon, pt.ngaytra)-ctpm.songayquydinh),0)
  17.     from PhieuMuon pm join PhieuTra pt on (pm.mapm = pt.mapm) join CT_PhieuTra ctpt on (pt.mapt= ctpt.mapt) join CT_PhieuMuon ctpm on (ctpm.mapm= pm.mapm)
  18.     where pm.mapm = @mapm
  19.  
  20.     if @@ROWCOUNT >0 return 0
  21. go
  22. /*
  23. select * from CT_PhieuTra
  24. select * from PhieuMuon
  25. select * from CT_PhieuMuon
  26. select * from PhieuTra
  27. */
  28. exec usp_Cau11 N'PM001',N'1/16/2014'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement