I'm looking for a query/script in MS SQL Server that will do the following:
Table1
| Project | Employee | Date | Comment |
| ------------ | ------------ | ------------ | ------------ |
| 1111 | 007 | 23-02-01 | Found Bad Guy |
| 1111 | 007 | 23-02-01 | NULL |
| 1112 | 007 | 23-02-18 | Drank Martini |
| 1112 | 007 | 23-02-18 | NULL |
I need a way to replace the NULL
s with the appropriate comment for that same day, but only if the project/date is the same (not put Martini on the 1111 project). So the final result should look like this...
Project | Employee | Date | Comment |
---|---|---|---|
1111 | 007 | 23-02-01 | Found Bad Guy |
1111 | 007 | 23-02-01 | Found Bad Guy |
1112 | 007 | 23-02-18 | Drank Martini |
1112 | 007 | 23-02-18 | Drank Martini |
I'm not going to know which projects or which dates have the null comment, but would be ok if I have to run it twice if there are two null's for the same date with one having the comment. I'm only going to be able to search a date range >= '2023-02-01' I have edited the above to respond to questions and better clarification
3条答案
按热度按时间khbbv19g1#
zu0ti5jz2#
Just updating some NULL values..
First determine the new value for that column
and use this query in an UPDATE statement:
see: DBFIDDLE
dgsult0t3#
Its works with mysql and postgres
Scenario 1:Nested Query works with postgres and mysql
Scenario 2:Using Join works with mysql
Scenario 3:works with MIcrosoft SQL Server tested on this Site
Scenario 4:This join is also works with Microsoft Server tested on this Site