Teste

0

Please login or register to vote for this query.

(click on this box to dismiss)

Joomla Meta

Q&A about the site for Joomla! administrators, users, developers and designers

CREATE table #Empresa
    ([Id] int, [EmpresaNome] varchar(30))
;
CREATE table #Contato
    ([Id] int, [IdEmpresa] int, [ContatoNome] varchar(30), [ContatoFone] varchar(30))
;
    
INSERT INTO #Empresa
    ([Id], [EmpresaNome])
VALUES
    (1, 'Empresa1'),
    (2, 'Empresa2'),
    (3, 'Empresa3')
;

INSERT INTO #Contato
    ([Id], [IdEmpresa],[ContatoNome],[ContatoFone])
VALUES
    (1,1, 'Contato1emp1', '1111'),
    (2,1, 'Contato2emp1', '2222'),
    (3,2, 'Contato3emp2', '3333'),
    (4,2, 'Contato4emp2', '4444')
;

select e.*,
( 
  SELECT ',' + ContatoNome AS 'data()', ContatoFone AS 'data()'
         FROM #Contato where idEmpresa = e.Id FOR XML PATH('')
) as contatos
from #Empresa as e

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results