Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pull Multiple Phone Records On Contact Row
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01463756
Message ID:
01463825
Vues:
48
>Hi Kev,
>
>Something's not right. Here's my queries
>
>
>SELECT RecordId, FirstName, LastName FROM Contacts WHERE LastName = 'marois'
>RecordId    FirstName   LastName
>-------------------------------------------------------
>4010        Kevin      Marois
>
>
>
>SELECT * FROM Phones WHERE ContactId = 4010
>RecordId    ContactId   PhoneTypeId PhoneNum
>----------- ----------- ----------- --------------------------------------------------
>58920       4010        4           +19513920229
>58921       4010        1           +19512233208
>
>SELECT * FROM PickLists WHERE ItemType = 'phone'
>RecordId    Caption                        ItemType
>----------- ------------------------------ --------------------
>1           Home                           phone
>2           Office                         phone
>3           FAX                            phone
>4           Cell                           phone
>5           Other1                         phone
>6           Other2                         phone
>7           Other3                         phone
>
>SELECT ContactId, [1] AS [Home], [2] AS Office, [3] AS Fax, [4] AS Cell, [5] AS [Other1], [6] AS [Other2], [7] AS [Other3]
>	FROM Phones
>    PIVOT (MIN(PhoneNum) FOR PhoneTypeID IN ([1], [2], [3], [4], [5], [6], [7])) TempList
>	WHERE ContactId = 4010
>
>ContactId   Home            Office     Fax		  Cell            Other1     Other2     Other3
>----------- --------------- ---------- ---------- --------------- ---------- ---------- ----------
>4010        NULL            NULL       NULL       +19513620229    NULL       NULL       NULL
>4010        +19512433208    NULL       NULL       NULL            NULL       NULL       NULL
>
>
>Notice that I'm getting back 2 rows. Never used Pivot tables before, so I'm not entirely sure what's wrong.

I must be missing something. I only see two records in the phone table (1 and 4) and that matches your final result. What should you be getting in your final resultset?
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform