Skip to content
Advertisement

Transform void record based on matching non void record

I have to transform 4 fields when certain conditions happen.
The VOID (type = 6) lines have to be transformed with the non VOID (type 0,2). The Transaction is unique for each line and the VOID line has the originating Transaction in the Voidtran field.

Here’s my query:

Here is what the data looks like and how I want the outcome to look: enter image description here

I think I need to build a UNION query – one part for Type 0 or 2 and one part for Type 6 but I don’t know how to change the 4 fields. All help is greatly appreciated!

Advertisement

Answer

If I understand correctly, you want to “spread” values when one is NULL. This uses COALESCE() and window functions:

I have no idea why you are casting values to strings (especially values that seem to already be strings), so I just removed that logic.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement