Jump to content
Fivewin Brasil

Ajuda em instrução SQL


leo@lhsistemas.com

Recommended Posts

Boa tarde.

Preciso de ajuda para montar o codigo abaixo em instrução SQL:

Function _BEstoque(cCod,dDataUlt)
Local nQtde := 0

** cCod = Codigo do Produto

** dDataUlt = Data da Ultima Atualização do Estoque

Set SoftSeek On
MOV02->( DbsetOrder(2), DbSeek(StrZero(Val(cCod)+1,14)) )
Set SoftSeek Off

If MOV02->Cod_Prod != cCod
MOV02->( DbSkip(-1) )
EndIf

nQtde := 0 // Quantidade Apudada no Estoque pela movimentacao do produto

dDtE := Ctod("") // Data Entrada
dDtS := Ctod("") // Data Saida

Do While MOV02->(! Bof()) .and. MOV02->Cod_Prod = cCod

If MOV02->Data_Doc < dDataUlt
Exit
Endif

If MOV02->Operacao = "E"
nQtde -= MOV02->quantidade

If MOV02->Data_Doc > dDtE
dDte := MOV02->Data_Doc
Endif

Else
nQtde += MOV02->quantidade

If MOV02->Data_Doc > dDtS
dDtS := MOV02->Data_Doc
Endif

EndIf

MOV02->( DbSkip(-1) )
EndDo

Return(nQtde,dDtE,dDtS)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...