Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15714

SQL - Selecting non-null value of a column when sequence number is max

$
0
0
Hi
I have a challenge where I need to know the value of a column but only when there is a non-null value in it and also the nun-null record is the latest sequentially for that specific column.

So, I have a table which I use to preserve traceability. Anything changes, a new row is inserted containing the changes (from and to) and the sequence of change for each case number is incremented.
Each relevant field has two columns "From_XX" and To_XX". If a case is changed, those columns will hold the value what is changed form and to. If the change does only concerns specific field then the rest of the fields will contain nulls except for those field where a change of value is applied.
All good with capturing the changes however, what I need now is to see the latest value for each column.

For example I need to know what is the value for the field called "To_MyName" for 30 cases.

If that can be also done for multiple columns (instead of only "To_MyName" then e.g. "To_MyName1" and "To_MyName2" ), it would be perfect.

her eis my thoughts but I get nothing:
Code:

SELECT TopOrder.To_AlignmentQA As LastQA 
FROM DV_Arena_Treacablity_Cases A
INNER JOIN
(SELECT To_AlignmentQA, MAX(ModificationOrder) AS MAXStuff
FROM DV_Arena_Treacablity_Cases
GROUP BY To_AlignmentQA
) As TopOrder

ON A.To_AlignmnetQA = TopOrder.To_AlignmentQA
AND A.ModificationOrder = TopOrder.MAXStuff
Where A.CaseID in ('1','2','3')

Thanks for any help.

Viewing all articles
Browse latest Browse all 15714

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>