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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CASE WHEN

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
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-04 : 07:20:11
select
case when SecondName = 'martinez' then 'martinamartinez@gmail.com'
when SecondName = 'laddstich' then 'marionladstich@gmail.com' end as email
from urtablename

Go to Top of Page

Borg
Starting Member

3 Posts

Posted - 2009-02-04 : 07:28:16
THANKS. I make it like

case
when 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
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-04 : 07:35:34
quote:
Originally posted by Borg

THANKS. I make it like

case
when 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
Go to Top of Page

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 like

case
when 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
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-02-04 : 09:21:46
can also do:


CASE SecondName
WHEN 'name1' THEN 'name1@email.com'
WHEN 'name2' THEN 'name2@email.com'
...END


Hearty head pats
Go to Top of Page

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 like

case
when 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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-04 : 10:51:50
cheers
Go to Top of Page
   

- Advertisement -