Sign up
Login
New
Trending
Archive
English
English
Sign up
Login
New Paste
Add Image
-- script de geração de recálculo de estoque após migração para uso de almoxarifado -- atualização: 20/01/2026 declare @dt_inicial date = '01.01.2015' declare @dt_final date = '31.12.2015' -- faturamento origem 41 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 41 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_lancamento , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(dt_emissao, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_notas_faturamento_itens a join tbl_notas_faturamento b on a.cd_lancamento = b.cd_lancamento join (select 41 cd_origem) o on o.cd_origem = 41 left join tbl_materiais_kardex_estoque est on a.cd_lancamento = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_lancamento = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_emissao between @dt_inicial and @dt_final and b.cd_empresa = 1 and (est.cd_id is null or alm.cd_item is null) union all -- emitidas saídas origem 43 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 43 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_nota , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(dt_emissao, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_notas_emitidas_itens a join tbl_notas_emitidas b on a.cd_nota = b.cd_nota join (select 43 cd_origem) o on o.cd_origem = 43 join tbl_tipo_documentos c on b.cd_tipodocumento = c.cd_tipodocumento and c.cd_operacao = 2 left join tbl_materiais_kardex_estoque est on a.cd_nota = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_nota = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_emissao between @dt_inicial and @dt_final and b.cd_empresa = 1 and c.cd_operacao = 2 and (est.cd_id is null or alm.cd_item is null) union all -- emitidas entradas origem 2 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 2 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_nota , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(dt_emissao, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_notas_emitidas_itens a join tbl_notas_emitidas b on a.cd_nota = b.cd_nota join (select 2 cd_origem) o on o.cd_origem = 2 join tbl_tipo_documentos c on b.cd_tipodocumento = c.cd_tipodocumento and c.cd_operacao = 1 left join tbl_materiais_kardex_estoque est on a.cd_nota = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_nota = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_emissao between @dt_inicial and @dt_final and b.cd_empresa = 1 and c.cd_operacao = 1 and (est.cd_id is null or alm.cd_item is null) union all -- compras origem 1 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 1 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_entrada , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(dt_emissao, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_compras_notafiscal_entrada_itens a join tbl_compras_notafiscal_entrada b on a.cd_entrada = b.cd_entrada join (select 1 cd_origem) o on o.cd_origem = 1 left join tbl_materiais_kardex_estoque est on a.cd_entrada = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_entrada = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_entrada between @dt_inicial and @dt_final and b.cd_empresa = 1 and (est.cd_id is null or alm.cd_item is null) union all -- requisição saídas origem 42 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 42 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_requisicao , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(dt_emissao, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_requisicao_itens a join tbl_requisicao b on a.cd_requisicao = b.cd_requisicao join (select 42 cd_origem) o on o.cd_origem = 42 left join tbl_materiais_kardex_estoque est on a.cd_requisicao = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_requisicao = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_emissao between @dt_inicial and @dt_final and b.cd_empresa = 1 and b.cd_operacao = 1 and (est.cd_id is null or alm.cd_item is null) union all -- requisição entradas origem 50 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 50 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_requisicao , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(dt_emissao, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_requisicao_itens a join tbl_requisicao b on a.cd_requisicao = b.cd_requisicao join (select 50 cd_origem) o on o.cd_origem = 50 left join tbl_materiais_kardex_estoque est on a.cd_requisicao = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_requisicao = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_emissao between @dt_inicial and @dt_final and b.cd_empresa = 1 and b.cd_operacao = 2 and (est.cd_id is null or alm.cd_item is null) union all -- contagens origem 100 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 100 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_lancamento , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(b.dt_lancamento, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_materiais_contagem_estoque_itens a join tbl_materiais_contagem_estoque b on a.cd_lancamento = b.cd_lancamento join (select 100 cd_origem) o on o.cd_origem = 100 left join tbl_materiais_kardex_estoque est on a.cd_lancamento = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_lancamento = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_lancamento between @dt_inicial and @dt_final and b.cd_empresa = 1 and (est.cd_id is null or alm.cd_item is null) union all -- produção consumo origem 46 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 46 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_entrada , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(b.dt_entrada, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_ordem_producao_consumo a join tbl_ordem_producao b on a.cd_entrada = b.cd_entrada join (select 46 cd_origem) o on o.cd_origem = 46 left join tbl_materiais_kardex_estoque est on a.cd_entrada = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_entrada = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_entrada between @dt_inicial and @dt_final and b.cd_empresa = 1 and (est.cd_id is null or alm.cd_item is null) union all -- produção produto produzido origem 4 -- declare @dt_inicial date = '01.01.2015', @dt_final date = '31.12.2015', @cd_origem int = 4 select concat('exec procedure_calcula_estoque @cd_empresa = ', b.cd_empresa , ', @cd_filial = ', b.cd_filial , ', @cd_origem = ', o.cd_origem , ', @cd_lancamento = ', a.cd_entrada , ', @cd_id = ', a.cd_id , ', @cd_material = ', a.cd_material , ', @dt_kardex = ', '''', format(b.dt_entrada, 'yyyyMMdd'), '''' , ', @x_estoque_almoxarifado = 1' , '; -- ', b.cd_filial ) script from tbl_ordem_producao_produto_produzido a join tbl_ordem_producao b on a.cd_entrada = b.cd_entrada join (select 4 cd_origem) o on o.cd_origem = 4 left join tbl_materiais_kardex_estoque est on a.cd_entrada = est.cd_lancamento and a.cd_id = est.cd_id_item_lancamento and est.cd_origem = o.cd_origem left join tbl_materiais_kardex_estoque_almoxarifado alm on a.cd_entrada = alm.cd_lancamento and a.cd_id = alm.cd_item and alm.cd_origem = o.cd_origem where b.dt_entrada between @dt_inicial and @dt_final and b.cd_empresa = 1 and (est.cd_id is null or alm.cd_item is null)
Settings
Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English