Skip to Content

Crystal Reports 2008

Olá pessoal,

Mais uma vez estou tendo dificuldades com o bendito Crystal Reports... Desta vez preciso de um relatório que me traga todos os cliente e informe se esse cliente é Pessoa Jurídica ou Pessoa Física. Segue SQL e uma imagem explicando melhor o meu problema.

SELECT "CRD7"."TaxId0", "OCRD"."CardName", "OCRD"."CardType", "CRD1"."Street", "OCRD"."Phone2", "OCRD"."Phone1", "OCRD"."Cellular", "CRD1"."City", "CRD1"."State", "CRD1"."ZipCode", "CRD1"."AddrType", "OCRD"."U_AGRO_REP", "CRD1"."Block", "CRD1"."StreetNo", "CRD7"."TaxId4", "CRD1"."Building"

FROM ("MEUBD"."dbo"."OCRD" "OCRD" INNER JOIN " MEUBD "."dbo"."CRD1" "CRD1" ON "OCRD"."CardCode"="CRD1"."CardCode") INNER JOIN " MEUBD "."dbo"."CRD7" "CRD7" ON "OCRD"."CardCode"="CRD7"."CardCode"

WHERE "OCRD"."CardType"='C'

Obrigado!

magazine_duvida.jpg (122.5 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jul 22, 2014 at 11:13 PM

    Boa noite Paulo,

    Inclui isso ai no seu select e testa, algo desse tipo deve funcionar...

    Case when

    "CRD7"."TaxId4" <> '' and "CRD7"."TaxId0" = ''

    Then 'F' else 'J' End As Tipo

    inclua no where AddrType = 'S' vai melhorar o resultado da sua consulta.

    Boa sorte!

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 24, 2014 at 06:06 PM

    Boa tarde,

    remova todas essas aspas, e remova também o nome do banco de dados, o Crystal Reports e o SAP já passam automaticamente o nome para sua select.

    Tente fazer a seguinte comando

    SELECT DISTINCT
    T0.CardCode,
    T0.CardName, 
    T0.CardType, 
    T1.Street, 
    T0.Phone2, 
    T0.Phone1, 
    T0.Cellular, 
    T1.City, 
    T1.State, 
    T1.ZipCode, 
    T1.AddrType, 
    T0.U_AGRO_REP, 
    T1.Block, 
    T1.StreetNo, 
    Convert(varchar(max), T1.Building) as Building,
    T2.TaxId0 as CNPJ,
    T2.TaxId4 as CPF, 
    CASE 
      WHEN ISNULL(T2.TaxId0,'') <> '' THEN 'J' 
      WHEN ISNULL(T2.TaxId4,'') <> '' THEN 'F'
      ELSE 'O' 
    END AS TipoFJ
    
    FROM 
    dbo.OCRD T0
    INNER JOIN dbo.CRD1 T1 ON T1.CardCode = T0.CardCode
    INNER JOIN dbo.CRD7 T2 ON T2.CardCode = T0.CardCode
    WHERE T0.CardType ='C' and  -- Somente Clientes
          T2.AddrType = 'S' -- Somente endereço destinatário
    ORDER BY T0.CardCode
    ORDER BY T0.CardCode
    

    Abraço

    Fabio.

    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.