I need to pick the first non null value for different columns for a particular id.
data scenario: the data is like this
ID C2 C3 C4 C5
-------- ------ ------ ------ ------
1000 32 A <NULL> 999
1000 <NULL> <NULL> Y 111
1000 <NULL> O N <NULL>
1000 22 <NULL> <NULL> 777
1001 <NULL> <NULL> <NULL> 666
1001 22 <NULL> Y <NULL>
1001 32 O <NULL> 555
Basically i have sorted it acocrding to id now i want is the id and the first non-null values for the rest of the columns.
my desired result is
DESIRED RESULT:
ID C2 C3 C4 C5
---- -------- ------ ------ ------
1000 32 A Y 999
1001 22 O Y 666
need help with getting the first non null value
Moderators: chulett, rschirm, roy
What 8.x version do you have? Normally the aggregator would help out for something like this but I don't think it is a viable option here due to needing the first value rather than say the max value. The Server aggregator supports first/last but I don't believe the parallel one does.
Failing that, it would seem that you could use stage variables to do the if-then-else checking needed and having at least version 8.5 would be best for that.
Failing that, it would seem that you could use stage variables to do the if-then-else checking needed and having at least version 8.5 would be best for that.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
The stage variables route would be pretty straight-forward. Setup one for each column and just do an if-then-else check to say if your SV is at its initial value and the column is non-null store the column value otherwise do nothing... and you do 'nothing' by setting the stage variable to itself, its current value.
Once you've processed the "last record in the group", output the result for all columns. Sorry but off the top of my head I don't recall the magical new thingie that lets you know that... function? System variable?
Once you've processed the "last record in the group", output the result for all columns. Sorry but off the top of my head I don't recall the magical new thingie that lets you know that... function? System variable?
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
Simpler version...
If sv_ID is null and In.ID is not null then In.ID else sv_ID
You shouldn't need to worry about the row number if the initial value is set appropriately, never mind the fact that you'd have to be very careful with it when running on multiple nodes.
If sv_ID is null and In.ID is not null then In.ID else sv_ID
You shouldn't need to worry about the row number if the initial value is set appropriately, never mind the fact that you'd have to be very careful with it when running on multiple nodes.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers