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
 Join 2 columns

Author  Topic 

kostlin
Starting Member

2 Posts

Posted - 2007-04-02 : 04:19:09
I have two colums within the same table. The 1st column contains name of products and the second column is used to rename the products so not every row is entered (omly those products we want to rename). I would like to create a new column which updates the name of the products. So if there is no new name it uses the old one, but if there is a new name use that one. I hope this makes sence?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-02 : 04:24:11
Table Structures, Sample Data and expected output, please.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

kostlin
Starting Member

2 Posts

Posted - 2007-04-02 : 04:57:54
Product name, New Product name, Restulting Product name to use
CCG, , CCG
ELNETT, ,Elnettie, Elnettie
ELV STY, , ELV STY
STUDIO, , STUDIO
ELVIVE, , ELVIVE
MEN, ,Mens, Mens


I have the first 2 columns but woudl like to create the resulting column.
I hope this is understandable?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-02 : 05:03:05
[code]declare @t table
(
prodname varchar(50),
newprodname varchar(50),
result varchar(50)
)

insert @t(prodname, newprodname)
select 'CCG', '' union all
select 'ELNETT', 'Elnettie' union all
select 'ELV STY', '' union all
select 'Studio', '' union all
select 'ELVIVE', '' union all
select 'Men', 'Mens'

update @t
set result = coalesce(nullif(newprodname, ''), prodname)

select * from @t[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -