Skip to Content

Erro ao gerar consultas no SAP

Bom dia,

Estou tentando rodar a seguinte consulta no SAP:

DECLARE @DATA1 AS Date, @DATA2 AS Date

SET @DATA1 = '[%0]'

SET @DATA2 = '[%1]'

--## Purchasing ##

SELECT 'NF Entrada' as Tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM OPCH T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27' union all

SELECT 'Devolução NF Entrada' as Tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM ORPC T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27' union all

SELECT 'Devolução de mercadoria' as Tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM ORPD T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27' union all

SELECT 'Recebimento de mercadoria' as tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM OPDN T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27' union all

--## Sales ##

SELECT 'NFSaida' as Tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM OINV T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27' union all

SELECT 'Entrega' as Tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM ODLN T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27' union all

SELECT 'Devolução' as Tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM ORDN T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27' union all

SELECT 'Devolução NF Saida' as Tipo,DocEntry,Serial,DocDate,CardName,CANCELED,DocStatus FROM ORIN T0 WHERE DocDate between @data1 AND @DATA2 AND SeqCode = '27'

No SQL Server essa consulta é executada com sucesso, já no SAP, está surgindo o seguinte erro:

1). [Microsoft][SQL Server Native Client 10.0]Invalid cursor state '' (SWEI)

Se eu mudar o DECLARE ele executa:

SET @DATA1 = '[%0]'

SET @DATA2 = '[%1]'


Vocês já tiveram esse problema?

Encontrei vários casos aqui, mas nenhum com uma solução que me auxilie.


Será que devo utilizar algum tipo de conversão ao passar as variáveis?


Att,

Maicon Macedo

SAP B1 9.0 PL10 HF 2

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Dec 08, 2015 at 01:41 PM

    Amigos do SCN,

    Eu descobri o problema: setar o valor na variável.

    Estava usando assim:

    SET @DATA1 = '[%0]'

    SET @DATA2 = '[%1]'

    Quando mudei para esse:

    SET @DATA1 = /* T0.DocDate */ '[%0]'

    SET @DATA2 = /* T0.DocDate */ '[%1]'

    Ela funcionou

    Att,

    Maicon Macedo

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 08, 2015 at 01:34 PM

    Olá Maicon,

    Como você preenche essas datas?

    Att,

    Diego

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.