Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to match records from different columns
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kkiranvr
Yak Posting Veteran

USA
54 Posts

Posted - 04/22/2009 :  13:11:38  Show Profile  Reply with Quote
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

United Kingdom
12543 Posts

Posted - 04/22/2009 :  13:13:34  Show Profile  Visit nr's Homepage  Reply with Quote
???

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

Sweden
30421 Posts

Posted - 04/22/2009 :  13:19:21  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

United Kingdom
12543 Posts

Posted - 04/22/2009 :  13:33:29  Show Profile  Visit nr's Homepage  Reply with Quote
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

Sweden
30421 Posts

Posted - 04/22/2009 :  13:36:49  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.34 seconds. Powered By: Snitz Forums 2000