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)
 Case when update

Author  Topic 

paull
Yak Posting Veteran

50 Posts

Posted - 2009-06-30 : 07:53:22
Hi all

I have a very quick (and I thought easy!) update to do on a table (V).

The table basically looks like..

ID Col1 Col2 Col3 NewCol1 Newcol2
123 aaa bbb ccc

I also have another table (F) which I need to get the condition

ID Q1 Q2 Q3
123 1 0 2

All I want to do is update NewCol1 with Col1 Where F.Q1=1. I thought this would be easy but I got stuck doing case whens and then trying to insert into a new table and ended up thoroughly confused!!!

I hoped for ...

UPDATE TableV v
Join TableF f

SET v.[NewCol1] =
Case when f.Q1 = 1 then v.[Col1] end






Any help would be greatly appreciated!

Thanks

P

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2009-06-30 : 08:45:21
moved from script library forum.

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.5 out!
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-06-30 : 09:20:34
update V
set V.newcol1 = V.col1
from TableV V inner join TableF F on V.ID = F.ID
where F.Q1 = 1

Go to Top of Page
   

- Advertisement -