July 18, 2005 at 4:05 am
Hi all: I'm stuck with a problem. I have a table with 2 cloumns say 'A' and 'B'. I have to update the values of 'B' with the corresponding 'A' value whenever 'B' is 'null'. How do i write it in a single update statement? How do I refer the value of the corresponding 'A' that is satisfying the 'where' condition.
update <table> set B=<'A' value of corresponding record> where B is null
July 18, 2005 at 5:07 am
Unless I'm misunderstanding...
Update tbl set B=A where B IS NULL
tbl Before
A | B |
---|---|
1 | a |
2 | NULL |
3 | NULL |
4 | d |
tbl After
A | B |
---|---|
1 | a |
2 | 2 |
3 | 3 |
4 | d |
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 18, 2005 at 5:55 am
thanx bud: thats wat i had in mind too. but wanted to confirm it b4 updating it on the live database. i think i shld have a backup in future.
July 18, 2005 at 6:22 am
I think you should get a dev/playground database where you can try stuff out before running on live.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 18, 2005 at 8:08 am
Quote:
i think i shld have a backup in future.
I think you should have a backup NOW!
-SQLBill
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply