Case statements: sql server : id	date	value
1	1	     null
1	2	     a
1	3	     b
1	4	     null
2	1	     null
2	2	     null
2	3	     null
2	4	     null
2	5	     null


if value is null in all id's then max of date of that id and if we have value then max of date with value id.


required like this:

id	date	value
1	3	        b
2	5	     null

