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.
Author |
Topic |
hai
Yak Posting Veteran
84 Posts |
Posted - 2008-11-26 : 14:58:00
|
Declare @tbl1 table(id int IDENTITY(1,1), VALIDX varchar(20))Declare @tbl2 table(id int )insert into @tbl1 select 'X' union allselect 'X' union allselect 'N' union allselect 'N' union allselect 'X' union allselect 'X' union allselect 'N' union allselect 'X' union allselect 'N' insert into @tbl2 select 1 union allselect 2 union allselect 3 union allselect 4 union allselect 5 union allselect 6 --RESET TO DEFAULT 'N'UPDATE @TBL1 SET VALIDX='N'--UPDATE TO 'X' IF MATCHUPDATE A SET VALIDX='X'FROM @TBL1 AINNER JOIN @TBL2 BON A.ID=B.IDas you can see I'm writing this in two parts, I know there is a much better way to rewrite this in a single update statement. Can someone point me to the right direction?thanks |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-11-26 : 15:04:15
|
UPDATE A SET VALIDX = (Case when A.ID = B.ID then 'X' else 'N' end)FROM @TBL1 Aleft outer JOIN @TBL2 BON A.ID=B.ID |
|
|
|
|
|