Skip to Content
0

Consulta formatada localização de Documento

Jan 23, 2017 at 02:17 PM

49

avatar image

Pessoal bom dia.

Preciso colocar essa consulta abaixo no sistema para consultar documentos, porem quando parametrizo a clausula where a consulta não funciona mais, alguem poderia me ajudar com essa ou com alguma outra consulta que tenham para localizar documentos no sistema:

SELECT 'NF Entrada', DocEntry, DocDate, Serial FROM OPCH WHERE Serial='4281' union all /* nf entrada*/ SELECT 'Devoluções', DocEntry, DocDate, Serial FROM ORDN WHERE Serial='4281' union all /*Devoluções*/ SELECT 'Dev. NF Saida', DocEntry, DocDate, Serial FROM ORIN WHERE Serial='4281' union all /*Devolução Nf Saída*/ SELECT 'Recebimento', DocEntry, DocDate, Serial FROM OPDN WHERE Serial='4281' union all /*Recebimento de mercadorias*/ SELECT 'NF Saida', DocEntry, DocDate, Serial FROM OINV WHERE Serial='4281' union all /* nf saida*/ SELECT 'Entrega', DocEntry, DocDate, Serial FROM ODLN WHERE Serial='4281' union all /*Entraga*/ SELECT 'Dev. NF Entrada', DocEntry, DocDate, Serial FROM ORPC WHERE Serial='4281' union all /*Devolução Nf Entrada*/ SELECT 'Devoluções de mercadoria', DocEntry, DocDate, Serial FROM ORPD WHERE Serial='4281' /*Devolução de Mercadoria*/

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Fabio Bilicki Jan 23, 2017 at 06:53 PM
0

Boa tarde.

Declare uma variavel antes, e utilize ela na sua consulta, lembrando que serial é int

O primeiro /* T0.Serial */ é pra enganar o SAP, assim ele sabe que é esse campo que deve ser solicitado.

DECLARE @SERIAL INT
SET @SERIAL = /* T0.SERIAL */ [%0]

SELECT 'NF Entrada', T0.DocEntry, T0.DocDate, T0.Serial FROM OPCH T0 WHERE T0.Serial=@SERIAL
union all 
SELECT 'Devoluções', T0.DocEntry, T0.DocDate, T0.Serial FROM ORDN T0 WHERE T0.Serial=@SERIAL
union all 
SELECT 'Dev. NF Saida', T0.DocEntry, T0.DocDate, T0.Serial FROM ORIN T0 WHERE T0.Serial=@SERIAL
union all 
SELECT 'Recebimento', T0.DocEntry, T0.DocDate, T0.Serial FROM OPDN T0 WHERE T0.Serial=@SERIAL
union all 
SELECT 'NF Saida', T0.DocEntry, T0.DocDate, T0.Serial FROM OINV T0 WHERE T0.Serial=@SERIAL
union all 
SELECT 'Entrega', T0.DocEntry, T0.DocDate, T0.Serial FROM ODLN T0 WHERE T0.Serial=@SERIAL
union all 
SELECT 'Dev. NF Entrada', T0.DocEntry, T0.DocDate, T0.Serial FROM ORPC T0 WHERE T0.Serial=@SERIAL
union all 
SELECT 'Devoluções de mercadoria', T0.DocEntry, T0.DocDate, T0.Serial FROM ORPD T0 WHERE T0.Serial=@SERIAL

[]'s

Fabio

SAP 9.1 PL11 / SAP 9.2 PL5 (test)

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Muito bom!

1
Ricardo Gardil Jan 23, 2017 at 07:05 PM
0

Muito bom mesmo obrigado!

Share
10 |10000 characters needed characters left characters exceeded