Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE dbo.CalcOst
- @KodSkl smallint,
- @PNT integer,
- @Ostatok decimal(18,5) OUTPUT
- AS
- declare @prod decimal(18,5),
- @KodPredpr int
- set @Prod=0
- set @Ostatok=IsNull(( Select Sum(Case DocCaption.VidDoc
- when 1 then IsNull(KolF,0)
- when 5 then IsNull(KolF,0)
- when 2 then -IsNull(KolF,0)
- when 3 then -IsNull(KolF,0)
- end)
- From DocString,DocCaption
- Where DocString.IdDoc=DocCaption.IdDoc and DocCaption.KodSkl=@KodSkl and DocString.PNT=@PNT),0)
- if exists (select * from master.dbo.sysdatabases
- where name ='Ditron')
- begin
- if ((select count(*) from tbPredpr where idPredpr =@KodSkl and idGrPredpr = ( select idGrPredpr from tbGrPredpr where nameGrPredpr = 'склад-магазин'))=1) and
- ((select count(*) from tbNastrSchet where IdPredpr=@KodSkl)=1)
- begin
- set @kodPredpr=(select kodpredpr from tbpredpr where idpredpr=@kodskl)
- set @prod=IsNull(( Select Sum(Ditron.dbo.tbProdaja.Kol)
- From Ditron.dbo.tbProdaja
- Where Ditron.dbo.tbProdaja.KodPredpr=@KodPredpr and
- Ditron.dbo.tbProdaja.PNT=@PNT ),0)
- set @Ostatok=@Ostatok-@prod
- end
- end
- GO
Add Comment
Please, Sign In to add comment