Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Ahamad
Starting Member
4 Posts |
Posted - 2015-03-12 : 16:57:28
|
Hi, I need a query to pull the data from Sql server. my requirement is i need to pull the data from multiple columns, in that there are three email fields are there like email1, email2, email3. i need query to retreive the data from table first it search for email in the above 3 fields if any one of the fields contains the record the it display as Main mail id. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2015-03-12 : 16:59:40
|
[code]select coalesce(email1, email2, email3) as MainMailIDfrom YourTable;[/code] |
|
|
Ahamad
Starting Member
4 Posts |
Posted - 2015-03-12 : 17:02:20
|
quote: Originally posted by James K
select coalesce(email1, email2, email3) as MainMailIDfrom YourTable;
|
|
|
Ahamad
Starting Member
4 Posts |
Posted - 2015-03-12 : 17:03:46
|
quote: Originally posted by James K
select coalesce(email1, email2, email3) as MainMailIDfrom YourTable;
If there is records in email1 as well as in email2 then how? |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2015-03-12 : 17:09:59
|
What do you want to see if there is data in email1 column and in email2 column? |
|
|
Ahamad
Starting Member
4 Posts |
Posted - 2015-03-12 : 17:27:39
|
quote: Originally posted by James K What do you want to see if there is data in email1 column and in email2 column?
Hi James,Thanks for quick response, Yes , i have to check whether data is there in Email1 ,email2 and email3 column , then if it is there then it should display as Main_Mail_ id. If there is email1 column is null then it has to search in email2 as well as in email3 like this. |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2015-03-13 : 08:21:04
|
quote: Hi James,Thanks for quick response, Yes , i have to check whether data is there in Email1 ,email2 and email3 column , then if it is there then it should display as Main_Mail_ id. If there is email1 column is null then it has to search in email2 as well as in email3 like this.
That is exactly what the query I posted in response to your original question does. Can you try to run that and see if you get the results you are looking for? |
|
|
|
|
|
|
|