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

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mathematica Meta

Q&A for users of Mathematica

CREATE table #yourtable
    (
    [LeadID] bigint, 
    [ContactType] varchar(6), 
    [ContactValue] varchar(13),
    [CanWeText] bit
    )
;
    
INSERT INTO #yourtable
    ([LeadID], [ContactType], [ContactValue], [CanWeText])
VALUES
    (1, 'Phone', '123456789', 0),
    (1, 'Cell', '987654321', 0),
    (1, 'Cell', '123456789', 1),
    (1, 'Email', 'a@gmail.com', 0),
    (4, 'Cell', '123456789', 1),
    (5, 'Phone', '123456789', 0)
;


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 sites:
loading Hold tight while we fetch your results