Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 SQL Query

Author  Topic 

Andrefonseca.info
Starting Member

2 Posts

Posted - 2010-05-24 : 15:17:05

I am creating a query that joins 2 tables, the first table has 3 salers code and the second has their names. The problem is when I execute the query it returns 3 rows, but, I need this information in one row.

Thanks,

Andre Santos

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-24 : 15:41:34
You'll need to post a data example to help illustrate your issue.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Andrefonseca.info
Starting Member

2 Posts

Posted - 2010-05-24 : 16:46:19
Ok, there it is,

That's my query:


select TVEN.CODVEN, TVEN.NOME AS VENDEDOR, FCFO.NOME AS CLIENTE, TTRBMOV.VALOR

from TMOV, TVEN, FCFO, TTRBMOV

where TMOV.CODCOLIGADA = TVEN.codcoligada and
(TMOV.CODVEN1 = TVEN.codven or
TMOV.CODVEN2 = TVEN.CODVEN or
TMOV.CODVEN3 = TVEN.CODVEN) and
TMOV.CODCOLCFO = FCFO.CODCOLIGADA and
TMOV.CODCFO = FCFO.CODCFO and
TMOV.CODCOLIGADA = TTRBMOV.CODCOLIGADA and
TMOV.IDMOV = TTRBMOV.IDMOV and
tmov.IDMOV='1947' and tmov.codtmv='2.1.01'


and that's the result:


05.000 MARIA ELIENE LOPES RECOFARMA INDÚSTRIA DA AMAZÔNIAS LTDA 515.0000
07.000 ANDRE LUIZ DA SILVA CARVALHO RECOFARMA INDÚSTRIA DA AMAZÔNIAS LTDA 515.0000
13.000 GABRIEL DE CARVALHO ROCHA RECOFARMA INDÚSTRIA DA AMAZÔNIAS LTDA 515.0000

I need the result as below, the codes and the names in the same row.

05.000 MARIA ELIENE LOPES 07.000 ANDRE LUIZ DA SILVA CARVALHO 13.000 GABRIEL DE CARVALHO ROCHA

Go to Top of Page
   

- Advertisement -