Bring result in a row to Join between tables with 1:N relationship

Asked

Viewed 51 times

-1

I have the following problem in SQL Server I have the tables CLIENTE and TELEFONE, with a relationship of 1:N among them:

CREATE TABLE CLIENTE(
       CPF CHAR(11) NOT NULL PRIMARY KEY
       , NOME VARCHAR(500)     
);

CREATE TABLE TELEFONE(
   ID_TELEFONE INT NOT NULL IDENTITY(1,1) PRIMARY KEY
   , CPF CHAR(11) NOT NULL
   , NUMERO VARCHAR(11)
   , CLASSIFICACAO INT DEFAULT(10)
   , FONTE VARCHAR(10)
   , DT_FONTE DATE
   , FOREIGN KEY (CPF) REFERENCES CLIENTE(CPF)
);

When I select with Join of the two tables returns like this:

CPF         |   NOME |   NUMERO

11111111111 |   jow1 |  992226801

11111111111 |   jow1 |  992226802

11111111111 |   jow1 |  992226803

11111111111 |   jow1 |  992226804

11111111111 |   jow1 |  992226805

11111111111 |   jow1 |  992226806

11111111111 |   jow1 |  992226807

11111111111 |   jow1 |  992226808

11111111111 |   jow1 |  992226809

11111111111 |   jow1 |  992226810

22222222222 |   jow2 |  26999861

22222222222 |   jow2 |  26999862

22222222222 |   jow2 |  26999863

22222222222 |   jow2 |  26999864

But I need you to return on a single line, like this:

CPF         |   NOME |   NUMERO_1 | NUMERO_2  |  NUMERO_3 |  NUMERO_4 | ...

11111111111 |   jow1 |  992226801 | 992226802 | 992226803 | 992226804 | ...

22222222222 |   jow2 |  26999861  | 26999862  | 26999863  | 26999864  | ...

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.