Skip to Content

Query pedido de compra

Estou fazendo uma consulta formatada e está com o seguinte erro no SQL.

Msg 156, Level 15, State 1, Line 37

Incorrect syntax near the keyword 'FROM'

Segue o Código

SELECT
A."CardCode" AS "FORNECEDOR",
F."CardName" AS "Nome",
C."DocNum" AS "SOLICITAÇÃO",
C."DocDate" AS "SOLICITAÇÃO - DATA",
C."ReqName" AS "SOLICITANTE",
A."DocNum" AS "PEDIDO",
A."DocDate" AS "PEDIDO - DATA",
B."LineNum" + '1' AS "PEDIDO - LINHA",
B."ItemCode" AS "PEDIDO - ITEM",
B."Dscription" AS "PEDIDO - DESCRIÇÃO",
B."Quantity" AS "PEDIDO - VALOR UNITARIO",
B."Currency" AS "PEDIDO - MOEDA",
B."Price" AS "PEDIDO - PREÇO UNITARIO",
B."DiscPrcnt" AS "PEDIDO - % DESCONTO",
D."DocNum" AS "NOTA FISCAL DE ENTRADA", CASE
WHEN B."TargetType" = '18' THEN 'NOTA FISCAL DE ENTRADA' | '-' | D."DocNum" | '- NFe Fornecedor: ' | D."DocNum"
WHEN B."TargetType" = '20' THEN 'RECEBIMENTO DE MERCADORIA' | ': ' | G."DocNum" | '- NFe FORNECEDOR: ' | G."Serial"

END AS "DOCUMENTO DESTINO", CASE
WHEN B."TargetType" = '18' THEN E."AcctCode" | '-' | J."AcctName"

END AS "CONTA CONTABIL", CASE
WHEN B."TargetType" = '18' THEN D."DocDate"
WHEN B."TargetType" = '20' THEN G."DocDate"

END AS "DATA RECEBIMENTO", --PEDIDO DE COMPRA FROM "OPOR" A
LEFT OUTER JOIN "POR1" B ON B."DocEntry" = A."DocEntry" --SOLICITAÇÃO DE COMPRA LEFT OUTER JOIN "OPRQ" C ON C."DocNum" = B."BaseDocNum" --NOTA FISCAL DE ENTRADA

LEFT OUTER JOIN "OPCH" D ON D."DocEntry" = B."TargetType"
LEFT OUTER JOIN "PCH1" E ON E."BaseEntry" = B."DocEntry" AND E."BaseLine" = B."LineNum" -- CADASTRO PARCEIRO DE NEGOCIOS LEFT OUTER JOIN "OCRD" F ON F."CardCode" = A."CardCode" --RECEBIMENTO DE MERCADORIA LEFT OUTER JOIN "OPDN" G ON G."DocEntry" = B."TargetType"
LEFT OUTER JOIN "PDN1" H ON H."DocEntry" = G."DocEntry" AND H."BaseLine" = B."BaseLine" --PLANO DE CONTAS LEFT OUTER JOIN "OACT" I ON I."AcctCode" = E."AcctCode"
LEFT OUTER JOIN "OACT" J ON J."AcctCode" = H."AcctCode"
WHERE A."CANCELED" = 'N'
AND A."DocDate" >= [%0]
AND A."DocDate" <= [%1] ORDER BY A."DocNum", B."LineNum"

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Mar 25 at 09:00 PM

    Hi,

    Try this query:

    SELECT
    A."CardCode" AS "FORNECEDOR",
    F."CardName" AS "Nome",
    C."DocNum" AS "SOLICITAÇÃO",
    C."DocDate" AS "SOLICITAÇÃO - DATA",
    C."ReqName" AS "SOLICITANTE",
    A."DocNum" AS "PEDIDO",
    A."DocDate" AS "PEDIDO - DATA",
    B."LineNum" + '1' AS "PEDIDO - LINHA",
    B."ItemCode" AS "PEDIDO - ITEM",
    B."Dscription" AS "PEDIDO - DESCRIÇÃO",
    B."Quantity" AS "PEDIDO - VALOR UNITARIO",
    B."Currency" AS "PEDIDO - MOEDA",
    B."Price" AS "PEDIDO - PREÇO UNITARIO",
    B."DiscPrcnt" AS "PEDIDO - % DESCONTO",
    D."DocNum" AS "NOTA FISCAL DE ENTRADA", CASE
    WHEN B."TargetType" = '18' THEN 'NOTA FISCAL DE ENTRADA' || '-' || D."DocNum" || '- NFe Fornecedor: ' || D."DocNum"
    WHEN B."TargetType" = '20' THEN 'RECEBIMENTO DE MERCADORIA' || ': ' || G."DocNum" || '- NFe FORNECEDOR: ' || G."Serial"
    END AS "DOCUMENTO DESTINO", CASE 
    WHEN B."TargetType" = '18' THEN E."AcctCode" || '-' || J."AcctName"
    END AS "CONTA CONTABIL", CASE 
    WHEN B."TargetType" = '18' THEN D."DocDate"
    WHEN B."TargetType" = '20' THEN G."DocDate"
    END AS "DATA RECEBIMENTO" --PEDIDO DE COMPRA 
    FROM "OPOR" A 
    LEFT OUTER JOIN "POR1" B ON B."DocEntry" = A."DocEntry" --SOLICITAÇÃO DE COMPRA 
    LEFT OUTER JOIN "OPRQ" C ON C."DocNum" = B."BaseDocNum" --NOTA FISCAL DE ENTRADA
    LEFT OUTER JOIN "OPCH" D ON D."DocEntry" = B."TargetType" 
    LEFT OUTER JOIN "PCH1" E ON E."BaseEntry" = B."DocEntry" AND E."BaseLine" = B."LineNum" -- CADASTRO PARCEIRO DE NEGOCIOS 
    LEFT OUTER JOIN "OCRD" F ON F."CardCode" = A."CardCode" --RECEBIMENTO DE MERCADORIA 
    LEFT OUTER JOIN "OPDN" G ON G."DocEntry" = B."TargetType"
    LEFT OUTER JOIN "PDN1" H ON H."DocEntry" = G."DocEntry" AND H."BaseLine" = B."BaseLine" --PLANO DE CONTAS 
    LEFT OUTER JOIN "OACT" I ON I."AcctCode" = E."AcctCode"
    LEFT OUTER JOIN "OACT" J ON J."AcctCode" = H."AcctCode"
    WHERE A."CANCELED" = 'N'
    AND A."DocDate" >= [%0]
    AND A."DocDate" <= [%1] ORDER BY A."DocNum", B."LineNum"
    

    Regards,

    Bala

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 26 at 01:25 AM

    Dear Samuel,

    END AS "DATA RECEBIMENTO", --PEDIDO DE COMPRA FROM "OPOR" A
    LEFT OUTER JOIN "POR1" B ON B."DocEntry" = A."DocEntry" --SOLICITAÇÃO DE COMPRA LEFT OUTER JOIN "OPRQ" C ON C."DocNum" = B."BaseDocNum" --NOTA FISCAL DE ENTRADA

    1) try to remove the comma

    2) FROM "OPOR" A, try to move to the next line. (Currently it is read as comment)

    Add comment
    10|10000 characters needed characters exceeded