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
 General SQL Server Forums
 New to SQL Server Programming
 Change output name

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-05-31 : 04:37:23
If data is cat or dog from animal column, then output for that column is Mammal.

Can I do that?

Animal
Mammal

mani_12345
Starting Member

35 Posts

Posted - 2012-05-31 : 05:27:53
update tab_name set animal = 'mamml'where animal in ('cat','dog')
Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-05-31 : 05:42:31
Not update.
What I meant is:

Select animal from tableA
where animal in ('dog','cat')

Animal Owner
dog Marry
cat Jane
snake Brian

What I want is to be like this:

Animal Owner
Mammal Marry
Mammal Jane
snake Brian

Can I do that?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-05-31 : 05:46:41
select
case
when animal in ('dog','cat') then 'Mammal'
else animal
end as animal,
owner
from tableA



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mani_12345
Starting Member

35 Posts

Posted - 2012-05-31 : 06:54:07
owner is your second column or both are same ?
Go to Top of Page

mani_12345
Starting Member

35 Posts

Posted - 2012-05-31 : 07:05:12
if u just want to replace it then use
this
:

select REPLACE(animal,'dog','mammal') from tab_name
select REPLACE(animal ,'cat','mammal') from tab_name
Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-05-31 : 23:26:56
owner is second column
Go to Top of Page

mani_12345
Starting Member

35 Posts

Posted - 2012-05-31 : 23:29:41


see my last post it will solve the problem whether u have single column or differnt column....
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-01 : 02:21:22
quote:
Originally posted by peace

owner is second column


Please see my given solution.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -