Row to Column - Phone Numbers

  • I am trying to do a query that is way over my head. I am trying to get phone numbers for student contacts. Each student may have 1-8 contacts with different phone numbers. I have looked at Pivot tables but just can't come up with the correct syntax.

    Example of data

    StudentID ContactType PhoneNumber

    1 Emergency Contact 6301234567

    1 Father 6302345678

    1 Mother 6303456789

    1 Emergency Contact 6304567890

    1 Emergency Contact 6309876543

    1 Emergency Contact 6308765432

    This needs to yield values for ONLY Emergency Contacts, one record, and only up to the first three Emergency Contacts (in rare cases there may be more than 3 but we are only interested in the first 3 hits)

    StudentID ContactType Emergency1 Emergency2 Emergnecy3

    1 Emergency Contact 6301234567 6304567890 6309876543

    I would certainly appreciate it if someone could assist with getting this to work.

    Thank you,

    Scott

  • Sorry about the double post.

    If a moderator could delete one it would be appreciated.

    Scott

  • Double-post...direct replies here: http://www.sqlservercentral.com/Forums/Topic1081364-149-1.aspx

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply