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)
 How to match records from different columns

Author  Topic 

kkiranvr
Yak Posting Veteran

54 Posts

Posted - 2009-04-22 : 13:11:38
I have a table and it is having 2 columns

Col1 Col2
120 390
124 null
138 null

140 450

Now i want the o/p as

Col1 Col2
120 390
124 124
138 138

140 450

Can any one suggest how to achieve this?

-Thanks N Regards,
Chinna.

nr
SQLTeam MVY

12543 Posts

Posted - 2009-04-22 : 13:13:34
???

update tbl
set Col2 = Col1
where Col2 is null



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-22 : 13:19:21
Or

SELECT Col1, COALESCE(Col2, Col1) AS Col1
FROM Table1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-04-22 : 13:33:29
Ah - o/p = output.

(s.b. "AS Col2" :) )


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-22 : 13:36:49
Thanks! I missed that one...

SELECT Col1, COALESCE(Col2, Col1) AS Col2
FROM Table1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -