-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 | ...