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 |
|
Borg
Starting Member
3 Posts |
Posted - 2009-02-04 : 07:07:20
|
| I have to make some case but don't know how to do it when I have 2 users. Example:case when SecondName = 'martinez' then 'martinamartinez@gmail.com'case when SecondName = 'laddstich' then 'marionladstich@gmail.com'how to make it in one command for both users? |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-04 : 07:19:13
|
| Try This,case when SecondName = 'martinez' then 'martinamartinez@gmail.com'when SecondName = 'laddstich' then 'marionladstich@gmail.com' End |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-04 : 07:20:11
|
| selectcase when SecondName = 'martinez' then 'martinamartinez@gmail.com' when SecondName = 'laddstich' then 'marionladstich@gmail.com' end as emailfrom urtablename |
 |
|
|
Borg
Starting Member
3 Posts |
Posted - 2009-02-04 : 07:28:16
|
| THANKS. I make it likecasewhen secondname = 'volfgan' then 'volfgan@gmail.com'when secondname = 'martrich' then 'martrichmartrich@gmail.com'when secondname = 'kraftwy' then 'kraftwy@gmail.com'else secondname end as emailaddress |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-04 : 07:35:34
|
quote: Originally posted by Borg THANKS. I make it likecasewhen secondname = 'volfgan' then 'volfgan@gmail.com'when secondname = 'martrich' then 'martrichmartrich@gmail.com'when secondname = 'kraftwy' then 'kraftwy@gmail.com'else secondname end as emailaddress
Welcome |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-04 : 08:38:54
|
quote: Originally posted by Borg THANKS. I make it likecasewhen secondname = 'volfgan' then 'volfgan@gmail.com'when secondname = 'martrich' then 'martrichmartrich@gmail.com'when secondname = 'kraftwy' then 'kraftwy@gmail.com'else secondname end as emailaddress
why do you check for each case and return a different email address? isnt it better to store email address value as a field inside table or even in another table withan id of user so that you can join to this table and show email in select statements rather than using case when to return each of values |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2009-02-04 : 09:21:46
|
can also do:CASE SecondNameWHEN 'name1' THEN 'name1@email.com'WHEN 'name2' THEN 'name2@email.com'...END Hearty head pats |
 |
|
|
Borg
Starting Member
3 Posts |
Posted - 2009-02-04 : 10:19:56
|
quote: Originally posted by visakh16
quote: Originally posted by Borg THANKS. I make it likecasewhen secondname = 'volfgan' then 'volfgan@gmail.com'when secondname = 'martrich' then 'martrichmartrich@gmail.com'when secondname = 'kraftwy' then 'kraftwy@gmail.com'else secondname end as emailaddress
why do you check for each case and return a different email address? isnt it better to store email address value as a field inside table or even in another table withan id of user so that you can join to this table and show email in select statements rather than using case when to return each of values
You are right. I will do it. But now I had to make like case when. Thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-04 : 10:51:50
|
| cheers |
 |
|
|
|
|
|