x

Separate sales codes by company

Hi,

In case of two companies, code 1 and code 2. Both have a customer with the same code. How to query only sales of customers in company 1?

 Company      CodeCustomer       CustomerName    Value
 1               980                       Paulo Silva            200,00 
 2               980                       Paulo Silva            150,00 

Thank you.

 SELECT  D.CODCOLIGADA AS 'COLIGADA CLIENTE' ,
         A.CODFILIAL ,
         A.CODTMV ,
         A.STATUS ,
         D.PESSOAFISOUJUR ,
         B.NOME ,
         A.DATAEMISSAO ,
         A.NUMEROMOV ,
         A.CODCFO ,
         D.NOMEFANTASIA ,
         C.VALORBRUTOITEM ,
         E.NOMEFANTASIA AS NOMEITEM ,
         A.USUARIOCRIACAO
 FROM    TMOV AS A
         INNER JOIN ttmv AS B ON A.CODCOLIGADA = B.CODCOLIGADA
                                 AND A.CODTMV = B.CODTMV
         INNER JOIN TITMMOV AS C ON A.CODCOLIGADA = C.CODCOLIGADA
                                    AND A.IDMOV = C.IDMOV
         INNER JOIN FCFO AS D ON A.CODCFO = D.CODCFO
         INNER JOIN TPRODUTO AS E ON C.IDPRD = E.IDPRD
 WHERE   A.CODTMV IN ( '2.2.01', '2.2.02', '2.2.03', '2.2.04', '2.2.05',
                       '2.2.06', '2.2.07', '2.2.08', '2.2.12', '2.2.13',
                       '2.2.14', '2.2.15', '2.2.16', '2.2.17', '2.2.18',
                       '2.2.19', '2.2.20', '2.2.21', '2.2.24', '2.2.25',
                       '2.2.26', '2.2.27', '2.2.28', '2.2.29', '2.2.30',
                       '2.2.31', '2.2.32', '2.2.33' )
         AND A.DATAEMISSAO >= '2016-01-01'
         AND A.NUMEROMOV = '21067'
more ▼

asked Jul 07 at 08:49 PM in Default

avatar image

Gelain
10 2

It could be as simple as adding a where clause and Company = 1 ?

Jul 10 at 09:39 AM Kev Riley ♦♦
(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x24

asked: Jul 07 at 08:49 PM

Seen: 95 times

Last Updated: Jul 10 at 09:39 AM

Copyright 2017 Redgate Software. Privacy Policy