Please start any new threads on our new site at 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
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query Help
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

56 Posts

Posted - 02/28/2013 :  16:57:08  Show Profile  Reply with Quote

I have one table with 5 columns

Comments, Table1, Table2, Table3, Table4
null, A, B, C, D
null, F, B, A, G
null, A, S, B, D
null, E, A, J, S

now i want to update like that

update t
set Comments = Comments + case when t.Table1 = 'A' then 'Table1--'
when t.Table2 = 'B' then 'Table2--'
from #temp

After update My Expected Result is

Comments, Table1, Table2, Table3, Table4
Table1--Table2, A, B, C, D
Table2, F, B, A, G
Table1, A, S, B, D
null, E, A, J, S

Please not suggest to check both column in same case as here I mention very simple condition actualy I have table with 150 columns and with different check and I want to mention comments when cretira match.


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 02/28/2013 :  23:34:23  Show Profile  Reply with Quote
the only other way i can think of is to unpivot the columns table1 to table150 in your case and then apply rules over rows obtained.

SQL Server MVP

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.02 seconds. Powered By: Snitz Forums 2000