CREATE table #yourtable ([LeadID] bigint, [ContactType] v...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Chinese Language

Q&A for students, teachers, and linguists wanting to discuss the finer points of the Chinese language

CREATE table #yourtable
    ([LeadID] bigint, [ContactType] varchar(6), [ContactValue] varchar(13))
;
    
INSERT INTO #yourtable
    ([LeadID], [ContactType], [ContactValue])
VALUES
    (1, 'Phone', '123456789'),
    (1, 'Cell', '987654321'),
    (1, 'Email', '[email protected]'),
    (4, 'Cell', '123456789'),
    (5, 'Phone', '123456789')
;


select LeadID, Phone, Cell, Email
from
(
  select LeadId, ContactType, ContactValue
  from #yourtable
) d
pivot
(
  max(ContactValue)
  for ContactType in (Phone, Cell, Email)
) piv;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results