Query Email Address

Last Post 16 Apr 2007 10:17 PM by SwePeso. 2 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
alejflor
New Member
New Member

--
16 Apr 2007 12:38 PM
Hi,
I have a table called ‘Email_Table’ that contains the email address for all of our students. In that table, there is an indicator that show if the email is (EMAIL_IND) school email or personal email.
Well, I want to create a query that will give me the email address for all students that have EMAIL_IND= School and if that is blank, then give me the email with the indicator set to EMAIL_IND=Personal.
I hope this make since.
Alex
SQLUSA
New Member
New Member

--
16 Apr 2007 05:26 PM
So EMAIL_IND can be

"School"
"Personal"
"" (blank)?

How about using the
WHERE EMAIL_IND = "School"

and similar?

Kalman Toth, Database Architect
SQL Server 2005 Training - http://www.sqlusa.com
SwePeso
New Member
New Member

--
16 Apr 2007 10:17 PM
If you prefer an *useful* answer, try something similar to this

SELECT StudentID,
COALESCE(School, Personal) AS eMail
FROM (
SELECT StudentID,
MIN(CASE WHEN EMAIL_IND = 'School' THEN NULLIF(eMail, '') END) AS School,
MIN(CASE WHEN EMAIL_IND = 'Personal' THEN NULLIF(eMail, '') END) AS Personal
FROM eMailTable
GROUP BY StudentID
) AS d
WHERE School IS NOT NULL
OR Personal IS NOT NULL
ORDER BY StudentID


Acceptable Use Policy
---