Guest User

Untitled

a guest
Oct 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. CREATE PROCEDURE dbo.CalcOst
  2. @KodSkl smallint,
  3. @PNT integer,
  4. @Ostatok decimal(18,5) OUTPUT
  5. AS
  6. declare @prod decimal(18,5),
  7. @KodPredpr int
  8. set @Prod=0
  9. set @Ostatok=IsNull(( Select Sum(Case DocCaption.VidDoc
  10. when 1 then IsNull(KolF,0)
  11. when 5 then IsNull(KolF,0)
  12. when 2 then -IsNull(KolF,0)
  13. when 3 then -IsNull(KolF,0)
  14. end)
  15. From DocString,DocCaption
  16. Where DocString.IdDoc=DocCaption.IdDoc and DocCaption.KodSkl=@KodSkl and DocString.PNT=@PNT),0)
  17. if exists (select * from master.dbo.sysdatabases
  18. where name ='Ditron')
  19. begin
  20. if ((select count(*) from tbPredpr where idPredpr =@KodSkl and idGrPredpr = ( select idGrPredpr from tbGrPredpr where nameGrPredpr = 'склад-магазин'))=1) and
  21. ((select count(*) from tbNastrSchet where IdPredpr=@KodSkl)=1)
  22. begin
  23. set @kodPredpr=(select kodpredpr from tbpredpr where idpredpr=@kodskl)
  24. set @prod=IsNull(( Select Sum(Ditron.dbo.tbProdaja.Kol)
  25. From Ditron.dbo.tbProdaja
  26. Where Ditron.dbo.tbProdaja.KodPredpr=@KodPredpr and
  27. Ditron.dbo.tbProdaja.PNT=@PNT ),0)
  28. set @Ostatok=@Ostatok-@prod
  29. end
  30. end
  31.  
  32.  
  33.  
  34.  
  35. GO
Add Comment
Please, Sign In to add comment